TinyXML2 を使用して、ディスクから xml ドキュメントをロードしています。
ファイルのパス (configFileName) はwstringであり、次のように文字列に変換しています。
tinyxml2::XMLDocument doc;
std::string fileName(configFileName.begin(), configFileName.end());
doc.LoadFile(fileName.c_str());
これは機能しますが、私のプログラムが中国語や韓国語などの 2 バイト OS で実行され、上記の wstring から string への変換で文字が失われる場合があります。
次のようなパスをロードするにはどうすればよいですか。
wstring wPathChinese = L"C:\\我明天要去上海\\在这里等我\\MyProgram";
編集
文字列を変換するために次のことを試みましたが、それでも漢字が壊れます。
std::string ConvertWideStringToString(std::wstring source)
{
//Represents a locale facet that converts between wide characters encoded as UCS-2 or UCS-4, and a byte stream encoded as UTF-8.
typedef std::codecvt_utf8<wchar_t> convert_type;
// wide to UTF-8
std::wstring_convert<convert_type, wchar_t> converter;
std::string converted_str = converter.to_bytes(source);
return converted_str;
}
string pathCh2 = ConvertWideStringToString(wPathChinese);