Well its me again.
I am trying to grasp the concept of reading and writing to files and was a bit confused on what the book was doing. So I decided to copy the example to see what was happening and I cant get the code to run. This is straight from the book and I get this error
fatal error C1083: Cannot open include file: 'stdlib': No such file or directory
ok so I changed it to <cstdlib> and I get the "error C2065: 'nocreate' : undeclared identifier"
Is the book out dated?
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib>
using namespace std;
int main()
{
const int MAXLENGTH = 21; //maximum file name length
const int MAXCHARS = 80; //maximum line length
char file1[MAXLENGTH] = "input.txt";
char line[MAXCHARS];
int ch;
ifstream inFile; //ifstream constructor opens the file
inFile.open (file1, ios::nocreate);
if (inFile.fail()) //checks for a successful open
{
cout << "\nThe file was not successfully opened"
<< "\n Please check that the file currently exists."
<< endl;
exit (1);
}
cout << endl;
while( (ch = inFile.peek()) != EOF )
{
inFile.getline(line, MAXCHARS, '\n');
cout << line << endl;
}
inFile.close();
cout << endl;
return 0;
}