This works, its essentially the same you had though. I added code to flush the keyboard buffer after each integer input. That may have been your problem.
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class dt
{
public:
int month,day,year;
dt() {month = day = year = 0;}
};
class EmailHeader
{
public:
string to;
string from;
string subject;
dt Date;
};
//overloaded input operator
istream& operator>>(istream& is, vector<EmailHeader>& ehVec)
{
EmailHeader headerInput;
cout << "Enter an email Header: Ctrl-Z to quit" << endl;
while(getline(is,headerInput.to))
{
getline(is, headerInput.from);
getline(is, headerInput.subject); //crash occurs here on second iteration after the
cout << "month: "; // user hits the return key, so input below is skipped
is >> headerInput.Date.month;
is.ignore();
cout << "day: ";
is >> headerInput.Date.day;
is.ignore();
cout << "Year: ";
is >> headerInput.Date.year;
is.ignore();
ehVec.push_back(headerInput);
cout << "Enter another email Header: Ctrl-Z to quit" << endl;
}
return is;
}
int main()
{
vector<EmailHeader> emVec;
cin >> emVec;
//other code
return 0;
}