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

inFile.open(RES_FILENAME.c_str());

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]

Thank you. That did the trick.

Terri

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.