Original Post
I'm working on some basic file IO. I can output to files just fine, but I can't seem to input to files. I have a file called ints.doc. It has the numbers 5, 6, 7, 8 in it, except without commas and with spaces. Whenever I read in the values I get random values, like the variables aren't being filled with anything. I'm sure I'm making some small mistake, but I just can't figure it out. In case it matters, I'm on a mac using Xcode 2.0. Thanks
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream inputStream;
int n1, n2, n3, n4;
inputStream.open("ints.doc");
if(inputStream.fail())
{
cout << "Failed to open file.";
return -1;
}
inputStream >> n1 >> n2 >> n3 >> n4;
cout << n1 << " " << n2 << " " << n3 << " " << n4;
inputStream.close();
return 0;
}