Careful, do the names contain white space? When using the extraction operator (>>) it will read everything until the next chunk of whitespace. So if your file looks like:
John Doe
Mary Smith
Your vector will contain 4 elements:
vec[0] == "John"
vec[1] == "Doe"
vec[2] == "Mary"
vec[3] == "Smith"
if you want the newline to represent your delimeter you'll have to use the std::getline function to read a line of text at a time. Example:
std::ifstream fin("input.txt");
std::string person;
std::vector<std::string> names;
while (std::getline(fin, person))
{
names.push_back(person);
}
|