I'm trying to read the contents of a file using the ifstream constructs. I've written a program that is a carbon copy off the website, under Reading From a File:
C++ Binary File I/O
Code:
1 #include <fstream>
2 using namespace std;
3 int main() {
4 char buffer[100];
5 ifstream myFile("temp", ios::in);
6 myFile.read(buffer, 100);
7 if(!myFile) {
8 fprintf(stderr, "Fail\n");
9 }
10 }
There is a file called temp in the directory where the program was built and the executable is handled. Everytime I execute the program, it prints "Fail." The file temp has chmod 777.
The heck is going wrong here?