Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.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++:将wstring转换为无符号字符_C++_Casting - Fatal编程技术网

C++:将wstring转换为无符号字符

C++:将wstring转换为无符号字符,c++,casting,C++,Casting,我试图将wstring转换为无符号字符。 我试过了,但这不存在 在"世界贸易组织"模式中是否有转变? 谢谢。嗯,我现在是这样做的: wstring sThis=L"12"; unsigned int i; i=_wtoi(sThis.c_str()); unsigned char c=(unsigned char)i; 我是这样做的 wstring wsWideString UINT uSize = wsWideString.length(); unsigned char * ptrUCh

我试图将wstring转换为无符号字符。 我试过了,但这不存在

在"世界贸易组织"模式中是否有转变?


谢谢。

嗯,我现在是这样做的:

wstring sThis=L"12";

unsigned int i;
i=_wtoi(sThis.c_str());

unsigned char c=(unsigned char)i;
我是这样做的

wstring wsWideString
UINT uSize = wsWideString.length();
unsigned char * ptrUChar = new unsigned char[uSize+1];
memset(ptrUChar ,'\0',uSize+1);
for(UINT i=0;i<uSize;i++)
{
ptrUChar [i] = wsWideString[i];
}

//when finished
delete [] ptrUChar ;
ptrUChar  = NULL;

我能想到的最接近的可能的重复,大概你的意思是“到一个无符号字符数组”,输入编码UCS-2,UTF-16,。。。?你想要什么样的输出编码?ASCII码?UTF-8?EBCDIC?@csl,你的副本只是关于散列的指针转换。我怀疑OP想要转换字符串内容,而不仅仅是抛出指针。这纯粹是魔术!将宽字符分配给字符,可节省50%的成本。伟大的压缩比!但说真的:这周我看到的最糟糕的代码。当存在std::deque或std::vector时,为什么要使用new和memset?既然尺寸已经存在,为什么还要使用一些合成的UINT?等等等等等等。