class Unicodecvt : public std::codecvt<wchar_t, char, mbstate_t> { protected: virtual bool do_always_noconv() const { return true; } }; // Writting std::wofstream fOut(L"D:\\test.txt", std::ios_base::binary); fOut.imbue(std::locale(std::locale(""), ::new Unicodecvt)); fOut << wchar_t(0xFEFF); // write BOM (UTF-16LE) fOut << L"유니코드 출력 테스트: " << 12345 << std::endl; fOut.close(); // Reading std::wifstream fIn(L"D:\\test.txt", std::ios_base::binary); fIn.imbue(std::locale(std::locale(""), ::new Unicodecvt)); if ( fIn.is_open() ) { fIn.seekg(2); // Skip BOM while ( !fIn.eof() ) { wchar_t wszBuf[1024] = { 0, }; fIn.getline( (wchar_t*)wszBuf, _countof(wszBuf)); } } fIn.close();
참조 문서
https://golbenge.wordpress.com/2009/12/24/stl을-이용한-unicode-텍스트-파일-출력 http://saneh.tistory.com/entry/STL-유니코드-저장읽기
No comments :
Post a Comment