I'm trying to process fragments of a text file that look like this:
6
Jane Doe
1942
90089
3 1 5 12
Lines 2-5 begin with a tab. The last line will have an arbitrary number of integers separated by spaces. I'm store all of this information in appropriate variables, with the last line in a vector. Here's what I've tried so far:
int id;
ifile >> id;
string name;
getline(ifile, name);
int year;
ifile >> year;
int zip;
ifile >> zip;
vector<int> friends;
string friends_str;
getline(ifile, friends_str);
istringstream iss(friends_str);
int x_id;
while (iss >> x_id) {
friends.push_back(x_id);
}
Am I missing anything about how tabs are dealt with? Is my approach with istringstream good for this situation, since the last line will have an unknown number of integers? Am I missing any trivial mistakes?