Search code examples
c++unicodeunicode-string

C++ output Unicode in variable


I'm trying to output a string containing unicode characters, which is received with a curl call. Therefore, I'm looking for something similar to u8 and L options for literal strings, but than applicable for variables. E.g.:

const char *s  = u8"\u0444";

However, since I have a string containing unicode characters, such as:

mit freundlichen Grüßen

When I want to print this string with:

cout << UnicodeString << endl;

it outputs:

mit freundlichen Gr??en

When I use wcout, it returns me:

mit freundlichen Gren

What am I doing wrong and how can I achieve the correct output. I return the output with RapidJSON, which returns the string as:

mit freundlichen Gr��en

Important to note, the application is a CGI running on Ubuntu, replying on browser requests


Solution

  • On my system the following produces the correct output. Try it on your system. I am confident that it will produce similar results.

    #include <string>
    #include <iostream>
    using namespace std;
    
    int main()
    {
        string s="mit freundlichen Grüßen";
        cout << s << endl;
        return 0;
    }
    

    If it is ok, then this points to the web transfer not being 8-bit clean.

    Mike.