2016/10/04
wofstream을 이용하여 한글 출력하기
wchar_t 문자열을 그대로 텍스트 파일에 출력하기위해 wofstream 객체에 << 연산자를 이용하였다. 잘 되는가 싶었는데 한글을 포함하여 기대대로 동작을 하지 않았다. 그래서 방법을 찾아보니 locale 설정을 해 주어야 한다고 한다. 전역으로 설정하던지 아니면 wofstream을 생성하고 해당 객체에 대해서 imbue함수를 이용하여 locale을 설정해 주면 된다.
1 2 3 4 5 6 | std::locale::global(std::locale( "Korean" )); // 방법 #1 std::locale::global(std::locale( "" )); // 방법 #2 wofstream fsOut; fsOut.imbue(std::locale( "Korean" )); // 방법 #3 fsOut.imbue(std::locale( "" )); // 방법 #4 fsOut.open( L "Output File Path" , std::ios::out ); |
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment