Here is Lithorien's example except with strings:
Code:
#include <iostream>
#include <string>
int main()
{
std::string names[200];
for (int i = 0; i < 200; i++)
{
std::cout << "Enter your name: ";
std::getline(std::cin, name[i]);
}
for (int i = 0; i < 200; i++)
{
std::cout << name[i] << "\n";
}
return(0);
}
If you are doing this for a class, then I don't know whether you should be using strings if your instructor has not yet taught them. However, if you're teaching yourself, or your instructor doesn't mind, I'd recommend learning and using the string class instead of character arrays. They are easier for a new programmer to understand, in my opinion, and harder to screw up.
I have to disagree with Lifedragn. You shouldn't have to worry about memory usage with such a small app, especially if you're a beginner and especially if it's only 200 strings. That's nothing. Chances are, if you are a beginner, you'd benefit from the string class much more than you'd ever have to worry about memory efficiency. If you are advanced enough to have to worry about memory efficiency, then you should be able to use a custom allocator or find some other solution that allows you to use string class and its benefits. I'm not saying that there is never a reason to use simple char arrays in C++, but generally strings are better.