Create Directory in Text Editor

Dec 5, 2011 at 1:40pm
Hello everyone,
I am writing a simple Text Editor. At the end of the program, I want to output a *.txt file in a directory the user wants. I know that in order to create directory and subdirectories, I can use this:

SHCreateDirectory(NULL, L"D:\\test\\example");

I want the user to create directories himself. Such as:
main()
{
string link;
std::cin>>link;
}
and user can type: D:\\test\\example

I wonder how I can connect the variable link with the command SHCreateDirectory. Or can I use another command ?

Thanks for your help
Dec 5, 2011 at 4:38pm
Pass it as the second parameter.

 
SHCreateDirectory(NULL, link.c_str());

You have to use c_str() because the function expects a char array, not a std::string.
Dec 5, 2011 at 5:06pm
Thanks, I am trying to do this:

void main()
{
string link;
cin>>link;
SHCreateDirectory(NULL, link.c_str());
}

It returns error: argument of type "const char*" is incompatible with parameter of type "LPCWSTR"
Dec 5, 2011 at 5:36pm
Use std::wstring in that case or use MultiByteToWideChar() API.
Topic archived. No new replies allowed.