Search code examples
c++netbeansunicodeutf-8netbeans-8.1

Netbeans C++ not printing UTF-8 characters


Here is the very simple C++ code:

char a00 = 'Z';
char a01 = '\u0444';
char a02[5] = {'H','e','l','l','o'};
char a03[] = {'W','o','r','l','d','\0','Z','Z'};

cout << "Simple char: " << a00
        << "\nUTF-8 char: " << a01
        << "\nFull char array: " << a02
        << "\n2nd in char array: " << a02[1]
        << "\nWith null character: " << a03 << endl;

My problem is when Netbeans 8.1 tries to show the output of such a program, it does not create the UTF-8 character.

The character should look like this: ф (see: link)

Instead, I get the following output:

(image)

I have tried adding -J-Dfile.encoding=UTF-8 to netbeans_default-options inside the netbeans.conf file located at inside the etc folder. It made no difference.


Solution

  • UTF-8 is a multibyte character encoding which means most of the characters occupy several bytes. So a single char is not enough to hold most UTF-8 characters.

    You can store them in a string like this:

    std::string s = "\u0444";