Click to See Complete Forum and Search --> : [RESOLVED] using a string to open a file for reading


Gulyman
June 13th, 2008, 04:33 PM
I'm making a program that does accounting. It's a school project that is self directed since I'm the only one in the class. I'm teaching myself.

In the program I store each persons data in a txt file with their username as the name of the file. When they enter the username I add it to a string and add .txt on the end. Poof, the file path to the file I need to read data from is created. I do this


ifstream inData;
inData.open(finalPath);


finalPath is the string with the file path.

The compiler doesn't like this. Since a string won't work, how else can I do this?

Philip Nicoletti
June 13th, 2008, 05:40 PM
open() takes a const char * variable ... assuming that finalPath is
a std::string, call the .c_str() member function ...


inData.open(finalPath.c_str());

Gulyman
June 18th, 2008, 07:10 PM
Thank you.