Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将LPCSTR转换为WCHAR*?_C++_String - Fatal编程技术网

C++ 如何将LPCSTR转换为WCHAR*?

C++ 如何将LPCSTR转换为WCHAR*?,c++,string,C++,String,如何将LPCSTR转换为WCHAR*为Unicode项目?我在网上找不到太多的东西。参考这个 或 如果您是非包括AtlBase.h或AtlConv.h标题 #include <windows.h> LPCSTR lpcszTemp = "Hello World" ; int wchars_num = MultiByteToWideChar( CP_UTF8 , 0 , lpcszTemp , -1, NULL , 0 ); WCHAR* wstr = new WCHAR[wc

如何将LPCSTR转换为WCHAR*为Unicode项目?我在网上找不到太多的东西。

参考这个


如果您是包括
AtlBase.h
AtlConv.h
标题

#include <windows.h>

LPCSTR lpcszTemp = "Hello World" ;

int wchars_num =  MultiByteToWideChar( CP_UTF8 , 0 , lpcszTemp  , -1, NULL , 0 );
WCHAR* wstr = new WCHAR[wchars_num];

MultiByteToWideChar( CP_UTF8 , 0 , lpcszTemp  , -1, wstr , wchars_num );
// ...Other codes...
delete[] wstr;
#包括
LPCSTR lpcszTemp=“你好,世界”;
int wchars_num=MultiByteToWideChar(CP_UTF8,0,lpcszTemp,-1,NULL,0);
WCHAR*wstr=新的WCHAR[wchars_num];
多字节towidechar(CP_UTF8,0,lpcszTemp,-1,wstr,wchars_num);
//…其他代码。。。
删除[]wstr;

在发布问题之前,您应该搜索类似的问题。这适用于不同的类型:
LPC T STR
。因此,它使用了错误的宏。