You're going to have problems because of the way your overloaded operator>> is defined.
Code:
istream& operator >> (istream& inFile, Person& p)
{
static const auto delimiter = ';';
getline(inFile, p.name, delimiter);
copy(istream_iterator<int>(inFile), istream_iterator<int>(), back_inserter(p.vec));
//inFile.clear();
return inFile;
}
The getline() is fine, although you don't need to define a variable for the delimiter, just use a character constant instead ';'.
But your copy will not stop until it encounters a stream error, which in this case will happen when it tries to read the first character of the next line. The operator>> knows it can't insert a character in a numeric variable.
b. what is the right way to use clear() in this case, if at all?
I would recommend using a stringstream to process the lines. Something like:
Code:
istream& operator >> (istream& inFile, Person& p)
{
string temp;
getline(inFile, temp);
stringstream sin(temp);
getline(sin, p.name, ';');
copy(istream_iterator<int>(inFile), istream_iterator<int>(), back_inserter(p.vec));
return inFile;
}
Then the copy() operation will fail because it reaches the "eof()" of the stringstream but this failure will not effect the underling stream.
But normally when you encounter a stream error you need to clear() the stream error and then remove the offending data from the stream.
Jim