Yet another problem.

A very short simple program copied from a book:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main()
{
    const int 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 ===|


Any ideas?
I'm guessing MAX_PATH is a predefined macro. Either look it up somewhere, or use your own const variable and give it a different name.
Thanks, MAX_PATH is defined in windows.h, I just had to include it.
Topic archived. No new replies allowed.