2013-10-16 2 views
0

wstring을 unsigned char로 변환하려고했습니다. _wtoc 시도했지만이 존재하지 않습니다.C++ : wstring을 unsigned char로 변환

_wto 스타일의 변환이 있습니까?

감사합니다.

+1

가능한 중복처럼 할 \ * '] (http://stackoverflow.com/questions/7624310/convert-a-const-wchar-t-to-unsigned-char) – csl

+0

내가 생각할 수있는 가장 가까운 것은 [wcstombs] (http : // en .cppreference.com/w/cpp/string/multibyte/wcstombs) –

+1

아마도 '부호없는 문자 배열'을 의미 할 것입니다. 입력 인코딩은 무엇입니까 (UCS-2, UTF-16, .. .)? 그리고 어떤 출력 인코딩을 원하십니까? (ASCII? UTF-8? EBCDIC?) – Roddy

답변

0

글쎄, 지금과 같이 그 일을하고있다 :

wstring sThis=L"12"; 

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

unsigned char c=(unsigned char)i; 
0

나는 'const를 WCHAR \ _t \ *'에서 '서명 숯불로 변환 [이

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; 
+0

이것은 순수한 마법입니다! 넓은 문자를 char에 할당하면 50 %의 비용을 절약 할 수 있습니다. 뛰어난 압축률! 진지하게, 비록 : 최악의 코드는 이번 주에 보았습니다. 'std :: deque' 나'std :: vector'가있을 때'new'와'memset'을 사용하는 이유는 무엇입니까? 왜'size_t '가 이미있을 때 어떤 유형 ('UINT')으로 만든 것입니까? 등등. – IInspectable

+0

와우 .... 감사합니다. 코드를 소유하고 있습니다. – singh

관련 문제