I have a file that looks like:
Sister Act
Whoopi GoldBerg
Maggie Smith
Schwartz
Ardolino
Touch Stone Pictures
14
I am having trouble reading in the information and saving it to an object. I am not getting any error but I can not get program to read the information correctly.
My question is can anyone tell me what I need to change to make the my program read the file correctly.
Also each row can have multiple words and whitespace except for the integer in row 7.
string title, starName1,
starName2, producer,
director, prodCo;
int numCopies;
ifstream videoFile("videoDat.txt");
if (videoFile.is_open()) {
getline(videoFile, title);
getline(videoFile, starName1);
getline(videoFile, starName2);
getline(videoFile, producer);
getline(videoFile, director);
getline(videoFile, prodCo);
//getline(videoFile, numCopies); //compiler error
while (videoFile >> title >> starName1 >> starName2 >> producer >> director >> prodCo >> numCopies) {
//be able to do stuff with variables individually
}
}
I was thinking i needed to do something like:
while (getline(videoFile, title) && getline(videoFile, starName1) && getline(videoFile, starName2)
&& getline(videoFile, producer) && getline(videoFile, director) && getline(videoFile, prodCo) && videoFile >> numCopies) {
//be able to do stuff with variables individually
}