Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3029

UTF-8 Conversion

$
0
0
I'm transferring a unicode string from one program to another with UTF-8 encoding.

Program that is sending:

Code:

// Convert path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
CString arg = L" /PATH=\"" + CString(utf8_converter.to_bytes(path).c_str()) + L"\"";

Program that is retrieving:

Code:

// Restore original path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
std::wstring path = utf8_converter.from_bytes( argument );

Everything has worked fine, until running on a Japanese edition of Windows.

The "byte path" then looks something like "C:¥Users¥d✝?✝a ,?¥AppData¥Local¥Temp¥file.txt".

"from_bytes()" will throw an std::range_error exception "bad conversion".

The program works fine when working with Japenese writing inside paths in the English edition.

Please help. What could be causing the "bad conversion"?

Viewing all articles
Browse latest Browse all 3029

Latest Images

Trending Articles



Latest Images