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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -