#include <iostream>
#include <fstream>
#include <cstdlib>
usingnamespace std;
int main()
{
constint MAX_PATH = 256;
char filename[MAX_PATH+1];
cout << "Enter a file name: ";
cin.getline(filename, MAX_PATH);
ofstream file_out(filename);
if (!file_out) {
cout << filename << " could not be opened.";
cout << endl;
system("PAUSE");
return -1;
}
cout << filename << " was opened." << endl;
file_out << "I read the" << endl;
file_out << "news today," << endl;
file_out << "ooh boy.";
file_out.close();
system("PAUSE");
return 0;
}
The problem is line 8. Line 8 I added myself, it is not in the program in the book. The reason I added that line is because the program seemed to expect a constant called MAX_PATH and I was getting errors because it doesn't exist. Therefore I declared my own but I get a red mark on line 8 and a face full of this:
1 2 3 4 5
||=== writetxt, Debug ===|
C:\Users\Calvin\Documents\C++ Projects\writetxt\main.cpp||In function 'int main()':|
C:\Users\Calvin\Documents\C++ Projects\writetxt\main.cpp|8|error: expected primary-expression before 'const'|
C:\Users\Calvin\Documents\C++ Projects\writetxt\main.cpp|8|error: expected ';' before 'const'|
||=== Build finished: 2 errors, 0 warnings ===|