c++ - How do separate a string from a text file -
c++ - How do separate a string from a text file -
i have text file has info format this:
id last,first string
for example:
0 snow,john nothing
1 norris,chuck everything
how lastly name , first name stored separately?
to info file, did:
#include <fstream> int id; string str; string last; string first; int main() { ifstream myfile(ex.txt); myfile >> id; while (myfile) { (int = 0; < 4; i++) // amount of times i'll info 1 line { id = id; // some_structure.id = id, omit getline(myfile, last, ','); // think need utilize function getline whole line cout << id; cout << last; // print out whole line! } } }
ifstream myfile; string line; while (getline(myfile, line)) { istringstream ss(line); int id; ss >> id; string fullname; ss >> fullname; string firstname, lastname; { istringstream ss2(fullname); getline(ss2, lastname, ','); getline(ss2, firstname); } }
c++ string
Comments
Post a Comment