Convert string to TCHAR* in VC++?

2020-07-17 16:23发布

How to convert string to TCHAR* in VC++ ?

Thanks.

标签: visual-c++
3条回答
家丑人穷心不美
2楼-- · 2020-07-17 17:01
#include <atlstr.h>

String dir="hello world";
char * data = new char[dir.size() + 1];
copy(dir.begin(), dir.end(), data);
data[dir.size()] = '\0'; 
USES_CONVERSION;
TCHAR* directory = A2T(data);
查看更多
聊天终结者
3楼-- · 2020-07-17 17:03

If your project is Unicode, you need MultiByteToWideChar. Otherwise, just use str.c_str();

查看更多
Bombasti
4楼-- · 2020-07-17 17:10

I resolved it using (TCHAR*)str.c_str()

查看更多
登录 后发表回答