Wide strings not printing properly

Hi

I have written a small program to test if wide strings print properly:

1
2
3
4
5
6
7
8
9
10
11
12
13
...

ofstream fout;          /// O/P file

...

    fout << "raw string : " << R"(hello!)" << endl;
    fout << "UTF-8 string : " << u8"hello!" << endl;
    fout << "UTF-16 string : " << u"hello!" << endl;
    fout << "UTF-32 string : " << U"hello!" << endl;
    fout << "wchar_t string : " << L"hello!" << endl;

    fout << u8"Danish vowels: \u00E6 \u00F8 \u00E5" << endl;


Here's the O/P:


raw string : hello!
UTF-8 string : hello!
UTF-16 string : 0x46e0a8
UTF-32 string : 0x46e0c8
wchar_t string : 0x46e0a8
Danish vowels: æ ø å


I have these queries:
1) The UTF-16, UTF-32 and wchar_t strings print improperly. Why and what must I do to get correct O/P?

2) The Danish vowels print OK when sent to file. However, if I send them to cout (console window), different and strange characters appear.

 
    cout << u8"Danish vowels: \u00E6 \u00F8 \u00E5" << endl;


Now, incorrect characters appear in the console window. Why and how can I correct this?

I use Windows 10, 64-bit.

Thanks
closed account (E0p9LyTq)
Wide string output requires using the wide string output stream method: std::wcout

http://www.cplusplus.com/reference/iostream/wcout/?kw=wcout
Last edited on
Topic archived. No new replies allowed.