using string to name directory

Hey guys,

Alright I am making a program that will take the users input and combines it with my string that I named for my directory. My problem is when I am trying to use mkdir, it will not let me use the string as my source to create and create the folder there... Here is my code...

string dirName = "c:/Dev-Cpp/AA/";
string usrInput; // This is where the user inputed a string of their choice

// Combines the user input with directory info
dirName = dirName + usrInput;

mkdir(dirName);


Ok that was my first question... My next is, when I have made this folder named by the user, how would I refer to it when I am making a new file in that folder... Once again more code...

ofstream myfile(?? "/password.txt");
// where the ?? is, is where my problem is located, as you saw in the previous problem I combined the directory name with user input, now I want to refer to that string and add the "/password.txt" next to it to create a new text file in that directory...

Any help is appreciated... THANKKS!!
Last edited on
mkdir() takes a (const char*) as argument, not a string, so you have to say:

mkdir( dirName.c_str() );

Combine filenames by adding them:

string fileName = dirName + "/password.txt";

Hope this helps.
Haha, thanks a lot, that really helped!! I had just started reading into doing this with files and was wondering how the syntax would be for folder making but that worked!! Thanks Duoas!!
Topic archived. No new replies allowed.