简体   繁体   中英

C++ - How to convert String to wchar_t (Cyrillic)

I need to convert a string to a wchar_t . I have tried a lot of different approaches, but I keep having problems with Cyrillic text. When using wcout to debug, I keep getting wrong output, but when just using Latin characters, no problems arise.

So how can I convert a string containing Cyrillic characters to a wchar_t ?

upd: I found the problem, I made a mistake when used wcout to debug, I all time was getting wrong output. But i manually rechecked character codes and it is realy UTF-16 . I dont know how to make correct output UTF-16 into console by wcout , but it is not so important for me.

First you also need to know size of wchar_t that that library requires. It may be 16 or 32 bits on different systems. Then you can use std::wstring_convert::from_bytes . This SO answer can also be useful for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM