1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
string str("City College, 2014, Fall, Biology");
record rec;
size_t prev = 0, comma = str.find_first_of(',');
rec.schoolName = str.substr(prev, comma);
prev = comma + 1;
comma = str.find_first_of(',', prev);
rec.year = atoi(str.substr(prev, comma).c_str());
prev = comma + 1;
comma = str.find_first_of(',', prev);
rec.term = str.substr(prev, comma);
prev = comma + 1;
comma = str.find_first_of(',', prev);
rec.courseName = str.substr(prev, comma);
cout << rec.schoolName + ", " << rec.year << ", " + rec.term + ", " + rec.courseName + "\n";
| |