while (inFile >> str) {
inFile.getline(track.course, MAXLINE, ';');
inFile.getline(track.desc, MAXLINE, ';');
inFile.getline(track.date, MAXLINE, ';');
std::cout << track.course << track.desc << track.date;
}
The first line will read all chars into str
until it hits the first whitespace, so if your input is
CS162;Lab Due;04/20/2014
MTH251;Quiz;04/22/2014
it will read up to and including Lab
into str
.
The next three lines will read until they hit ;
, so your track struct will look as follows
course = "Due"
desc = "04/20/2014\nMTH251" // note the newline
date = "Quiz"
Changing the while
loop and changing the last extractor should fix this:
while (inFile) {
inFile.getline(track.course, MAXLINE, ';');
inFile.getline(track.desc, MAXLINE, ';');
inFile.getline(track.date, MAXLINE, '\n');
if (inFile)
std::cout << track.course << track.desc << track.date;
}
although it's worth mentioning that there are a number of things you can do here to simplify the code, including using std::string
instead of char
arrays, like this for instance.