Can't read all lines of file

I have a program that is supposed to read from a file, parse it, then output the results. I can't get getline to work, and I've tried every variation I can find, and everything says that they should be working, this is the code:

while (fileBefore >> preparse) {
unparsed.push_back(preparse);
}

The output I am receiving is just the first line of my text file, and it is supposed to read all lines. Thanks!
Last edited on
getline is the proper method to read a file line by line.
Try this simple demo.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
  ifstream src(__FILE__);
  string line;
  while (getline(src, line))
  {
    cout << line << "\n";
  }
}
No, I don't need to cout anything, I need to store it so I can manipulate it.

EDIT: I also tried an implementation that used that and it did not work.
Last edited on

while (fileBefore >> preparse) {

}
unparsed.push_back(preparse);
View the file in a hex editor and verify that it does not contain invalid characters.
See:http://www.cplusplus.com/forum/beginner/231403/#msg1044614

Note: "in particular, on Windows OS, the character '\0x1A' terminates input"
Thanks JLBorges, I was able to fix it after checking the file.
Topic archived. No new replies allowed.