Convert string to TCHAR* in VC++?

2020-07-17 16:25发布

问题:

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

Thanks.

回答1:

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



回答2:

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



回答3:

#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);


标签: visual-c++