string with fstream & designated directory

hi
im haveing a bit of a dilema. I am using this to create a txt file in a cetain place.

ofstream file("C:\\Documents and Settings\\All Users\\Documents\\filename.txt");
but i want the file name to be read from a string. I know you can use

string str
ifstream inputFile(str.c_str)

but i dont know how to make it work with the designated directory there aswell i have tried lots of things with quotes and what not, but i always get synax errors or literally make a file called "str.c_str"

is what i am trying to do posible this way?

thanks
c_str is a function so its: str.c_str()
um yes sory i didnt do that on my previous post but i did do it like that when i tried it in c++
ofstream file("C:\\Documents and Settings\\All Users\\Documents\\"str.c_str());
and i tried it with the quotes after that but neither work
Last edited on
1
2
string fileName = "C:\\Documents and Settings\\All Users\\Documents\\" + str.c_str();
ofstream file(fileName.c_str());
Shouldn't that be
1
2
string fileName = "C:\\Documents and Settings\\All Users\\Documents\\" + str;
ofstream file(fileName.c_str());
?
Last edited on
Errr yea, that's correct. I was in a hurry :P
Topic archived. No new replies allowed.