Hi guys/gals, I'm having a problem with a function that overloads the input stream. The problem is that the getline crashes on the second iteration of the while loop:
//overloaded input operator
istream& operator>>(istream& is, vector<EmailHeader>& ehVec)
{
EmailHeader headerInput;
cout << "Enter an email Header: Ctrl-D to quit" << endl;
while(getline(is, headerInput.to))
{
getline(is, headerInput.from);
// crash occurs after the user hits enter (second iteration)
getline(is, headerInput.subject);
is >> headerInput.Date.month;
is >> headerInput.Date.day;
is >> headerInput.Date.year;
ehVec.push_back(headerInput);
cout << "Enter another email Header: Ctrl-D to quit" << endl;
}
return is;
}
EmailHeader is a simple test class which holds string members for "From", "To", "Subject" fields and integer values for the dates.
I'm calling the overloaded input function from my main:
int main()
{
vector<EmailHeader> emVec;
cin >> emVec;
//other code
}
Any help and suggestions would be greatly appreciated. TIA.