How to convert string to wstring and wstring to string - how to deal with asian language in C++

preview_player
Показать описание
We learn how to convert multibyte char string or char* to wide character string, and wide character string or wchar_t* to multi byte char string.

We also learn how to convert std::string to std::wstring, and std::wstring to std::string.

To properly deal with asian languages such as Korean, Japanese, and Chinese in our software development, we need to install these languages on our development machine, also make proper system settings.

mbsrtowcs - multi byte string to wide character string

wcsrtombs - wide character string to multi byte string

Download source code:

Комментарии
Автор

I was struggling with string conversion for a long time. I needed a way to convert wide strings to regular strings, and vice versa. I've tried various methods, and none of them worked for me. Your functions work perfectly. I like your approach to problem-solving - attention to detail, handling all exceptions, and bulletproof code. Thank you very much!

dtrajko
Автор

哇哇 interesting solution! Thanks for the help

michaelborisow
Автор

Beautiful commenting, and easy to follow. I was here to see your approach on the conversion, but I am sure this example will be widely sought after in the coming years! Keep up the hard work.

NextToken
Автор

Hi Kim, thanks of your effort, very much appreciated. With regard to the video I've just watched, to do with string conversion, I think the problem is on the last statement.

std::wcout << "Converted: [" << wstr << "]\n";

You are trying to put multi-byte characters to wide characters stream. Now, writing the following

std::wcout << L"Converted: [" << wstr << L"]\n";

should just work. No need for the hack about locale here. I have no idea how you've managed to compiler your program under VC++ in the first place.

Keep up the good work.

josephamatagana
welcome to shbcf.ru