w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to read a file word by word and find the position of each word?

One simple way to solve this problem would be using std::getline, run your own counter, and split line's content into words using an additional string stream, like this:

string line;
int line_number = 0;
for (;;) {
     if (!getline(fin, line)) {
         break;
     }
     istringstream iss(line);
     string tmp;
     while (iss >> tmp) {
         mylist.push_back(tmp);
     }
     line_number++;
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.