views:

409

answers:

3

Example:

#include <iostream>

using namespace std;

int main()
{
    wchar_t en[] = L"Hello";
    wchar_t ru[] = L"Привет"; //Russian language
    cout << ru
         << endl
         << en;
    return 0;
}

This code only prints HEX-values like adress. How to print the wchar_t string?

+1  A: 

Can I suggest std::wcout ?

So, something like this:

std::cout << "ASCII and ANSI" << std::endl;
std::wcout << L"INSERT MULTIBYTE WCHAR* HERE" << std::endl;

You might find more information in a related question here.

Konrad
+4  A: 

Edit: This doesn’t work if you are trying to write text that cannot be represented in your default locale. :-(

Use std::wcout instead of std::cout.

wcout << ru << endl << en;
Nate
It prints only english string.What about russian?
zed91
You’re right: this fails if any character cannot be represented by the default locale. I don’t have a Russian-language system to test on. Unfortunately you will probably need to `imbue` `wcout` (and `wfstream` and so on) with a `facet` that can output in something other than the deafult locale.
Nate
The console is not going to be Unicode enabled. Output redirection is the hangup, that's stuck in 8-bit char legacy. It can only output correct text on a Russian machine with the correct console font loaded.
Hans Passant
A: 

You could use use a normal char array that is actually filled with utf-8 characters. This should allow mixing characters across languages.

Michael Speer