0

Hello,

I would like to be able to declare a filename as a global constant (so I can change the input file easily), which seems to be a simple thing to do, but I can't seem to get it to work.

I declared this globally:

const string RES_FILENAME = "RESIDENTS.TXT";

Then I tried using it later on in program:

inFile.open(RES_FILENAME);

to which I get error messages about no matching function. I tried to enclose RES_FILENAME inside the function with ' (such as 'RES_FILENAME'), and I get an error message about converting from int to const char. I tried goggling the problem, but can't seem to find a solution. Any help would be appreciated. Thank you!

Terri

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by teppuus
0

The open function does not take std::string object but a char*, so call its c_str() to get it

inFile.open(RES_FILENAME.c_str());

[edit]what Dave said ^^^^[/edit]

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.