Hey guys, I've been trying to figure out how to read in a list of integers from a text file using visual c++ express 2010, and I'm completely stumped. This is the kind of thing that I'm trying now:
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
int x;
ifstream myfile;
myfile.open ("text.txt");
if (!myfile) {
cout << "unable to load file.\n";
}
while (myfile >> x) {
cout << x << endl;
}
myfile.close();
system("pause");
return 0;
}
When I run this all I get is "press any key to continue..."
So the file is correctly read, but I can't do anything with the data.
text.txt contains integers on separate lines. Like this:
12
32
14
What am I doing wrong?