How to print wstring on Linux / OS X?

How can I print this line: €áa¢cée£on the console / screen? I tried this:

#include <iostream>    
#include <string>
using namespace std;

wstring wStr = L"€áa¢cée£";

int main (void)
{
    wcout << wStr << " : " << wStr.length() << endl;
    return 0;
}

which does not work. Even confusing if I remove from the line, the printout is as follows: ?a?c?e? : 7but with nothing in the line is printed after the character .

If I write the same code in python:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

wStr = u"€áa¢cée£"
print u"%s" % wStr

it displays the string correctly on the same console. What am I missing in C ++ (well, I'm just a noob)? Hooray!!


Update 1: nm-based suggestion
#include <iostream>
#include <string>
using namespace std;

string wStr = "€áa¢cée£";
char *pStr = 0;

int main (void)
{
    cout << wStr << " : " << wStr.length() << endl;

    pStr = &wStr[0];
    for (unsigned int i = 0; i < wStr.length(); i++) {
        cout << "char "<< i+1 << " # " << *pStr << " => " << pStr << endl;
        pStr++;
    }
    return 0;
}

First of all, it reports 14as the length of the string: €áa¢cée£ : 14Is it because it counts 2 bytes per character?

And all this I get:

char 1 # ? => €áa¢cée£
char 2 # ? => ??áa¢cée£
char 3 # ? => ?áa¢cée£
char 4 # ? => áa¢cée£
char 5 # ? => ?a¢cée£
char 6 # a => a¢cée£
char 7 # ? => ¢cée£
char 8 # ? => ?cée£
char 9 # c => cée£
char 10 # ? => ée£
char 11 # ? => ?e£
char 12 # e => e£
char 13 # ? => £
char 14 # ? => ?

as the last exit cout. Therefore, in my opinion, the actual problem remains. Hooray!!


2: n.m.

#include <iostream>
#include <string>

using namespace std;

wchar_t wStr[] = L"€áa¢cée£";
int iStr = sizeof(wStr) / sizeof(wStr[0]);        // length of the string
wchar_t *pStr = 0;

int main (void)
{
    setlocale (LC_ALL,"");
    wcout << wStr << " : " << iStr << endl;

    pStr = &wStr[0];
    for (int i = 0; i < iStr; i++) {
       wcout << *pStr << " => " <<  static_cast<void*>(pStr) << " => " << pStr << endl;
       pStr++;
    }
    return 0;
}

:

€áa¢cée£ : 9
€ => 0x1000010e8 => €áa¢cée£
á => 0x1000010ec => áa¢cée£
a => 0x1000010f0 => a¢cée£
¢ => 0x1000010f4 => ¢cée£
c => 0x1000010f8 => cée£
é => 0x1000010fc => ée£
e => 0x100001100 => e£
£ => 0x100001104 => £
 => 0x100001108 => 

9 8? , ? !!

+5
1

L . std::string, std::wstring.

UPD: () . wchar_t, wstring L setlocale(LC_ALL,"") .

setlocale(LC_ALL,"") . , . UTF-8, .

setlocale(LC_ALL,"") UTF-8 "", UTF-8. UTF-8, UTF-8, . , string char: gcc UTF-8 , ostream - . , ASCII.

wchar_t, : gcc UTF-32, ( - "C" ), - .

setlocale(LC_ALL,""), , UTF-32 UTF-8, dandy .

, UTF-8. .

+7

All Articles