cvt is initialized in the default code. What is the behavior of this default built-in codecvt?
. Windows .
(, , ) std :: string, wchar_t ?
++ 11 std::codecvt_utf8_utf16. , , C++17, " , ".
, :
boost::filesystem::path::imbue(
std::locale( std::locale(), new std::codecvt_utf8_utf16<wchar_t>() ) );
path::string() UTF-16 UTF-8.
- std::wstring_convert< std::codecvt_utf8_utf16<wchar_t> > .
:
#include <boost/filesystem.hpp>
#include <iostream>
#include <codecvt>
void print_hex( std::string const& path );
int main()
{
boost::filesystem::path path( L"\u00c4\u00d6\u00dc" );
print_hex( path.string() );
boost::filesystem::path::imbue(
std::locale( std::locale(), new std::codecvt_utf8_utf16<wchar_t>() ) );
print_hex( path.string() );
std::wstring_convert< std::codecvt_utf8_utf16<wchar_t> > cvt;
print_hex( cvt.to_bytes( path.wstring() ) );
}
void print_hex( std::string const& path )
{
for( char c : path )
{
std::cout << std::hex << "0x" << static_cast<unsigned>(static_cast<unsigned char>( c )) << ' ';
}
std::cout << '\n';
}