I am trying to read data from a file in which the data is semicolon delimited. Example:
The Lord of the Rings: The Fellowship of the Ring;Jackson, Peter;2001;178;93000000;871530324
Above is all one entry. There is also a number in the first line of the file stating the number of entries. Each entry is on a different line. I am trying to read in this data to a vector of structs called info. The struct is named MovieData.
vector<MovieData> readFile(string fName,MovieData info, int& numOfMovies){
vector<MovieData> movies;
ifstream fin;
fin.open(fName);
fin >> numOfMovies;
cout << "Number of Movies: " << numOfMovies << "\n";
for(int i=0;i<numOfMovies;i++){
getline(fin, info.Title, ';');
getline(fin,info.Dir, ';');
getline(fin,info.year, ';');
getline(fin,info.time, ';');
getline(fin,info.cost, ';');
getline(fin, info.revenue);
info.profit = info.revenue - info.cost;
movies.push_back(info);
}
return movies;
}
I am having trouble with reading in the data from the file using getline(), but I believe I have everything else correct.