1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
#include <sstream>
#include <string>
// Test data
std::istringstream in(
R"("Memento",2000,"R","Mystery/Thriller",113,0
"The Good, the Bad and the Ugly",1966,"APPROVED","Western",161,0
)");
int main()
{
std::string title, rating, genre;
int year, runTime, avgScore;
char ch;
while (in >> ch) // read initial double-quote
{
getline(in, title, '"');
in >> ch; // comma
in >> year;
in >> ch >> ch; // comma and dquote
getline(in, rating, '"');
in >> ch >> ch; // comma and dquote
getline(in, genre, '"');
in >> ch; // comma
in >> runTime;
in >> ch; // comma
in >> avgScore;
std::cout << title << '\n'
<< rating << '\n'
<< genre << '\n'
<< year << '\n'
<< runTime << '\n'
<< avgScore << "\n\n";
}
}
|