I have a csv file that has data like so: 03/10/2016 09:10:10 PM, Name, Genre
and I have loaded operators that read in the date as integers (DD/MM/YY) and time as integers (HH:MM:SS) and the PM as char, Name and Genre as strings. Here's my code:
In my Time class:
istream & operator >> (istream & is, Time & time)
{
char colon;
is >> time.hour >> colon >> time.minute >> colon >> time.second >> time.PM;
return is;
}
and my Date class
istream & operator >> (istream & is, Date & date)
{
char slash;
is >> date.day >> slash >> date.month >> slash >> date.year;
return is;
}
I read in my file in another class like so:
string line; //declaration
Show show; //declaration
while (!inFile.eof())
{
inFile >> date;
cout << "Date = " << date.getDay() << "/" << date.getMonth() << "/" << date.getYear()<< endl;
inFile >> time;
cout << "Time = " << time.getHour() << ":" << time.getMinute() << ":" << time.getSecond() << " " << time.getPM() << " " << endl;
getline(inFile, line, ',');
show.setName(line);
cout << "Name = " << line << endl;
getline(inFile, line, ',');
show.setGenre(line);
cout << "Genre = " << line << endl;
showVector.push_back(show) //pushback the objects into a vector<Show> showVector
}
So basically, as you can see, I printed out what the program reads in to test and there's just a small issue:
Date = 16/11/2004
Time = 9:30:20 P
Name = M
Genre = House, Medical Drama
Why is the M in PM being skipped over and assigned to the Name?