std :: string到LPCTSTR [英] std::string to LPCTSTR
问题描述
新版本的典型问题如何从 std :: string
转换为 LPCTSTR
。
阅读不同的SO文章我知道我应该这样做:
CreateDirectory (path.c_str(),NULL);
然而编译器给出错误,因为不能从const char *转换为LPCTSTR
我试过:
CreateDirectory((LPCTSTR)path.c_str(),NULL);
没有错误!
创建(在正确的位置)被调用:
D:\\something\\㩄ぜ弲㩄ぜ弲䅓余屓䱆彄湡敤屲䵉ⴱ㠶ⴰⵃㅇ㉜洰就䥄牃獥汵獴촀췍췍췍췍췍췍췍﷽ꮫꮫꮫذوو
这不是我想要的,你可以猜到...
那么我缺少什么?它是与UNICODE / ANSI有关的东西吗?
您的问题在于 LPCTSTR $ c $ c>根据您的构建是否支持unicode(unicode标志设置或不是)来解析为
wchar_t *
或 char *
。
要显式调用 char *
版本,请调用 CreateDirectoryA c $ c>。
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 this:
CreateDirectory(path.c_str(),NULL);
And still the compiler gives error because cannot convert from const char * to LPCTSTR
.
I tried:
CreateDirectory((LPCTSTR)path.c_str(),NULL);
No errors!
Still the directory created (in the correct place) is called:
D:\\something\\㩄ぜ弲久䅓余屓䱆彄湡敤屲䵉ⴱ㠶ⴰⵃㅇ㉜洰就䥄牃獥汵獴촀췍췍췍췍췍췍췍﷽ꮫꮫꮫﺫﻮﻮ
which is not exactly what I wanted, as you can guess...
So what am I missing? Is it something related with UNICODE/ANSI? How can I resolve this?
Your problem here is the fact that LPCTSTR
is resolved to wchar_t*
or char*
based on whether your build supports unicode (unicode flag set or not).
To explicitly call the char*
version, call CreateDirectoryA()
.
这篇关于std :: string到LPCTSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!