Reading text file line by line in c++ -


i want read text text file c++ code. here code:-

f.open(input); if (f) {        while(!f.eof())     {         linkedlist obj;         string c, d, l;         f>>c>>d>>l;          nodes.push_back(c);         nodes.push_back(d);          vector<string> temp;         temp.push_back(c);         temp.push_back(d);         temp.push_back(l);         vecnodes.push_back(temp);     }  } 

my text file below:

a b c c d e e g h 

my question how can read 1 line @ 1 time. when code read second line go read first character of third line wrong. know can put delimiter @ end of each line might work. there other way this?

you can read line line file following code :

string line; ifstream myfile; myfile.open("myfile.txt");  if(!myfile.is_open()) {     perror("error open");     exit(exit_failure); }  while(getline(myfile, line)) {     // things here } 

then split space string , add elements in list.


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -