简体   繁体   中英

C++: Converting wstring to unsigned char

I tried to convert a wstring to unsigned char. I tried _wtoc, but this does not exists.

Is there a conversion in the _wto style?

Thank you.

Well, I am doing it like this now:

wstring sThis=L"12";

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

unsigned char c=(unsigned char)i;

I do it like this

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM