반응형

http://kimbeast.blog.me/60036942254



라이브러리 만들던중 문득 나중에 UNICODE로 만들게 되면.? 이라는 의문에 unicode출력 테스트를 하게 되었다.

환경 (gcc 4.1.x, opensuse 10.2)


#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#include <iostream>

using namespace std;
int main()
{
setlocale(LC_ALL, "ko_KR.utf8");

wchar_t *wstring3 = L"한글Alpha";

wcout << wstring3 << endl;

return 0;
}


위와 같이 하니.잘 나왔다.
그래서 라이브러리에 집어넣고 출력을 봤더니만. .아무것도 안 나오는 현상이 발생하였다.
원인이 뭘까..고민하던 차에 아주 황당한 결과를 보게 되었다.


#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#include <iostream>

using namespace std;
int main()
{
setlocale(LC_ALL, "ko_KR.utf8");

wchar_t *wstring3 = L"한글Alpha";

cout << wstring3 << endl;
wcout << wstring3 << endl;


return 0;
}


위와 같이 한다면..출력결과는???

cout 의 결과만 나온다.
wcout 의 결과는 엉망으로 나온다.

다시 반대로..


#include <stdio.h>
#include <wchar.h>
#include <locale.h>
#include <iostream>

using namespace std;
int main()
{
setlocale(LC_ALL, "ko_KR.utf8");

wchar_t *wstring3 = L"한글Alpha";

wcout << wstring3 << endl;
cout << wstring3 << endl;

return 0;
}


wcout 의 결과만 나온다.
cout 의 결과는안나온다.

즉 라이브러리안에 있던 cout 문장이 출력에 영향을 줘서 unicode 출력이 되지 않는 것이었다.

결론적으로 유니코드 base 로 만들려면 cout을 절대 사용하지 말란 말이 된다.
이게 어디 쉬운일인가? 잘 통제되지 않으면.그냥 출력한다고 cout넣을텐데 말이다.
오묘한 세계다...

반응형

'프로그래밍(Programming) > c++, 11, 14 , 17, 20' 카테고리의 다른 글

.ini 파일 클래스  (0) 2012.10.31
문자열 변환  (0) 2012.10.31
Timer - getElapsedMilliSecond  (0) 2012.10.31
C 언어에서 파일을 여는 함수 입니다. W/R 모드  (0) 2012.10.31
함수포인터  (0) 2012.10.31

+ Recent posts