utf8
문자를 내 std::strings
에 저장하고 싶습니다. 이를 위해 boost::locale
변환 루틴을 사용했습니다.부스트 로케일 생성기를 올바르게 사용하십시오.
#include <boost/locale.hpp>
std::string utf8_string = boost::locale::conv::to_utf<char>("Grüssen", "ISO-8859-15");
std::string normal_string = boost::locale::conv::from_utf(utf8_string, "ISO-8859-15");
예상되는 결과는 다음과 같습니다 :
utf8_string = "Grüssen"
normal_string = "Grüssen"
내가 사용하려고 문자열로 "ISO-8859-15"을 통과 없애 내 첫 번째 테스트 모두에서
는 예상대로 작동 std::locale
대신
// Create system default locale
boost::locale::generator gen;
std::locale loc=gen("ISO8859-15");
std::locale::global(loc);
// This is needed to prevent C library to
// convert strings to narrow
// instead of C++ on some platforms
std::ios_base::sync_with_stdio(false);
std::string utf8_string = boost::locale::conv::to_utf<char>("Grüssen", std::locale());
std::string normal_string = boost::locale::conv::from_utf(utf8_string, std::locale());
는하지만 결과는 예상과 : std::locale
와 발전기를 사용하여 내 사용을 잘못 무엇
utf8_string = "Gr|ssen"
normal_string = "Gr|ssen"
? 는 (컴파일러 VC2015, 멀티 바이트 캐릭터)가
결과를 어떻게 검사합니까? "utf8_string ="Grüssen ""을 기대하는 것은 이상합니다. 왜냐하면 본질적으로 "잘못된"디코딩을 기대하기 때문입니다. 또한, 소스 파일 인코딩은 무엇입니까? latin1이 아닌 다른 것이라면 틀립니다. – sehe
VC2015 디버거로 검사 한 결과 win32 TextOutA를 사용하여 utf8에서 다시 변환 된 normal_string을 인쇄했습니다. 메모장 + +는 파일 인코딩이 ANSI임을 알려줍니다. 글쎄, utf_8 문자열을 보려면 Grüssen은 "Grüsese"가 iso8859-1을 기대하는 것으로 렌더링 할 때 utf8로 인코딩 된 Grüsse가 보이는 방식이기 때문에 "우습지 않은"문자입니다. 그래서 std :: locale에서 잘못된 점은 무엇입니까? –