How exactly do I work with Japanese characters in C ++?

I am trying to make something as simple as this:

#include <iostream> #include <string> using namespace std; int main() { wstring nihongo = L"みんăȘたにほんご"; wcout << nihongo << endl; return 0; } 

But I get the following errors:

 C:\Users\Leonne\Leomedia\MetaDatterTest.cpp|7|error: stray '\201' in program| C:\Users\Leonne\Leomedia\MetaDatterTest.cpp|7|error: stray '@' in program| C:\Users\Leonne\Leomedia\MetaDatterTest.cpp||In function 'int main()':| C:\Users\Leonne\Leomedia\MetaDatterTest.cpp|7|error: converting to execution character set: Illegal byte sequence| ||=== Build finished: 3 errors, 0 warnings ===| 

I am on a Windows computer and I am trying to make the library as portable as possible, and it should be able to handle any characters: Russian, Japanese, ASCII, that's all.

+4
source share
2 answers

Check out the first answer to this question:

std :: wstring VS std :: string

and my answer to this is:

UTF-8 handling in C ++

I believe that you will find the answer to your question. Character encoding problems are a bit confusing stuff and there is no easy answer ...

+1
source

Support for Visual Studio unicode source files. Make sure your cpp files are saved in utf16 or utf8 format files with BOM . Once in this format your files will be compiled.

+3
source

Source: https://habr.com/ru/post/1386851/


All Articles