//flex table opened by JP

Click to See Complete Forum and Search --> : C++ question


nothing
09-09-2004, 10:29 AM
Here's the situattion:
1 - I ask the user to input the name for the file that is going to be created and store it in string filename.

2 - I ask the user to input the path where some files my program is going to work with are and store it in string directory.

What's the setup to created file "filename" in the directory "directory"?

Thank you.

fishybawb
09-09-2004, 10:49 AM
I'm not too sure what you're asking... If you want to create a complete path/filename from those two strings, concatenate them so the resulting string is composed of "directory", a '\' character, then "filename". Sorry, that's probably not what you want.

CompGeek01
09-09-2004, 11:11 AM
Open needs a const char* right? Have you
tried:


open(fileName.c_str(), ios::in);


I know a lot of time C++ doesn't like variables in places like that :t but there must be a way to do it.

nothing
09-09-2004, 11:12 AM
Hey, yes, I think that's what I want. To create a file which the name was specified by the user, I do something like this:

std::ofstream to_file(filename.c_str());


So I guess if I do something like

std::string path = directory + "\" + filename;

std::ofstream to_file(path.c_str());


it should work. Thanks for the idea fishybawb.