mbstowcs 함수가 이상해요.
글쓴이: kealyung / 작성시간: 화, 2008/02/19 - 3:26오후
typedef std::basic_string< wchar_t > WSTRING;
int main()
{
char chBuffer[1024];
char chBuffer2[1024];
memset(chBuffer, 0x00, sizeof(chBuffer));
memset(chBuffer2, 0x00, sizeof(chBuffer2));
setlocale(LC_CTYPE, "ko_KR.eucKR");
WSTRING Msg;
WSTRING Msg2;
sprintf(chBuffer, "%s", "메세지");
sprintf(chBuffer2, "%s", "message");
int a = mbstowcs((wchar_t*)Msg.c_str(), chBuffer,1000);
printf( "%x,%x,%x,%x\n",Msg[0], Msg[1], Msg[2], Msg[3]);
int b = mbstowcs((wchar_t*)Msg2.c_str(), chBuffer2,1000);
printf( "%x,%x,%x,%x\n",Msg[0], Msg[1], Msg[2], Msg[3]);
printf( "%x,%x,%x,%x\n",Msg2[0], Msg2[1], Msg2[2], Msg2[3]);
return 1;
}
[출력결과]
ba54,c138,c9c0,0
6d,65,73,73
6d,65,73,73왜 첫번째 줄의 결과와 2번째 줄의 결과가 다른거죠?
Forums:


할당되지 않은 메모리에
데이터를 썼으니 뭐가 나와도 이상하지 않습니다.
WSTRING Msg, Msg2 대신에
wchar_t Msg[1024], Msg2[1024] 를 사용하면 원하던 결과를 볼 수 있을 듯 합니다.
댓글 달기