0

I can read all string besides last "Yury Chen 88 3939202"

  ifstream file("text.txt");
  string s;
  int counter = 0;
  for(file >> s; !file.eof(); file >> s)
  {
    if (counter<=3){
      templist.push_back(s);
      counter +=1;
    }
    else{
      list.push_back(templist);
      counter = 0;
      templist.clear();
      templist.push_back(s);
      counter +=1;
    }
}

text.txt is

John        Jones        12  5412354
Kevin   Abatsa 23   6431264
Name    Surname      31    1239523
Yury Chen  88     3939202

Where is the problem?

1 Answers1

4

The problem is probably with:

for(file >> s; !file.eof(); file >> s)

When this streams the last string in the file - 3939202 - it's proabbly setting the eof flag, so you exit without processing that string. (We can't say for sure because we can't see if there's whitespace after 3939202 in your file...).

Just change to:

while (file >> s)
Tony Delroy
  • 102,968
  • 15
  • 177
  • 252