I am working on a project that involves a bit of directory manipulation. Until now i only had to create create directories as per user input, so till now the commnad mkdir worked fine:

But now i have to do some manipulations on the string to get the path.I have run into this problem where mkdir is not crating the directories when i pass a string variable as argumnet.
//str=(assigned something after manipulations);

Is there another way i can do this??

Thank you!

mkdir(str.c_str()); perhaps

its not working. gives me the following error

request for member `c_str' in something not a structure or union

i guess c_str is for c++, rather than c.

Oop. Sorry; my fault! I saw you mention a string and forgot this was C land - I'm so used to a string being a C++ string object and nowadays I never use the term in C.

Can you give some sample code that doesn't work?

Another hint: mkdir() only works on one directory at a time. You have to call mkdir() for each new directory in the directory hierarcy. If you want to create a directory "c:\one\two\three" then call mkdir("c:\one"), mkdir("c:\one\two") and finally mkdir("c:\one\two\three")

Thanks a lot Ancient Dragon. i was trying to create 3 directories at a time. Had to split it up with a for loop to make 1 directory at a time.

Thank you for the inputs, Moschops.

I know I am nitpicking, but the backslashes need to be doubled in: mkdir("c:\one\two\three").

Yes, like this: mkdir("c:\\one\\two\\three"). (you actully need four of them to post here because the editor removes two of them. That is escaping the escape character \)

/ worked fine for me actually.


/ worked fine for me actually.

Because / is not a backslash. \ is a backslash.

/ is far more portable and as a general rule is preferable to using \\