Reading external files, (not!!)
Hello all,
I am a complete newbie trying to learn this stuff. I actually have two questions;
1) I have been looking through a few of the recent threads and I have noticed some differences to my programming, (I'm using MicroSoft Visual Studio 6.0 by the way).
On this site's programs the header files are:-
Code:
#include <iostream>
#include <fstream>
On my programming I have to add .h to the header files. Why?
I'll post the second question on a different message.
Reading external files (not!!) Part 2.
I apologise for blathering on but I am really stuck on this problem.
I have an external file called "test.dat" from a write program. This bit actually works and the following code is supposed to read from it, but it doesn't. Why, please???
Code:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
const int max = 80;
int main ()
{
ifstream input_file;
char film[max];
input_file.open("test.dat",ios::in|ios::nocreate);
if (input_file.fail())
{
cout << "File does not already exist." << endl;
exit(1);
}
while (input_file.peek() != EOF)
{
input_file.getline (film, max);
cout << film <<endl;
}
cout << endl;
input_file.close();
return 0;
}
The program compiles OK but when it runs, the result is
"File does not already exist."
I am frustrated and confused. :confused: