|
-
June 13th, 2008, 04:33 PM
#1
[RESOLVED] using a string to open a file for reading
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
Code:
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?
-
June 13th, 2008, 05:40 PM
#2
Re: using a string to open a file for reading
open() takes a const char * variable ... assuming that finalPath is
a std::string, call the .c_str() member function ...
Code:
inData.open(finalPath.c_str());
-
June 18th, 2008, 07:10 PM
#3
Re: [RESOLVED] using a string to open a file for reading
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|