New version of the typical question of how to convert from std::string
to LPCTSTR
.
Reading from different SO posts I learnt that I should do th
You are compiling for Unicode which means that CreateDirectory
is an alias for CreateDirectoryW
, the wide character version. However, the text in your program is encoded using ANSI. This means that your program cannot handle internationalization properly.
The compiler is telling you that there is a mismatch between the text encoding that CreateDirectoryW
expects, and the text encoding that you are supplying. It's true that you could call CreateDirectoryA
to resolve that mis-match, but that is only going to perpetuate the root problem, the fact that you are using ANSI text in your program.
So, the best solution is to start encoding all your text as Unicode. Stop using string
and start using wstring
. Once you change path
to wstring
then
CreateDirectory(path.c_str(),NULL);
is correct.