I'm using TinyXML2 to load an xml document from disk.
The path of the file (configFileName) is a wstring and I am converting it to string like so:
tinyxml2::XMLDocument doc;
std::string fileName(configFileName.begin(), configFileName.end());
doc.LoadFile(fileName.c_str());
This works but there may be times where my program runs on a double byte OS such as Chinese or Korean and the conversion from wstring to string above will loose the characters.
How can I load a path such as the following:
wstring wPathChinese = L"C:\\我明天要去上海\\在这里等我\\MyProgram";
EDIT
I have tried the following to convert the string but it still corrupts the chinese characters:
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);