4

I've got a program like below:

#include <iostream>
using namespace std;
int main()
{
    wcout << "abc" << endl;
    cout << "你好" << endl;
    cout << L"abc" << endl;
    return 0;
}

My questions:

  1. The first "wcout" has no problem, my question is: does wcout "automatically" convert to narrow char string "abc" into wchar_t string L"abc" in memory, and print it? How can I prove if such conversion exists or not?

  2. The second "cout" print out a chinese charater string of "hello". It works as long as I set Chinese code-page in windows. No problem.

  3. The third "cout" will print "??" or random character in my test. I'm curious, why "cout" could print other language characters successfully, but not wchar_t string? What's the core problem/difference here?

Thanks.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
Hind Forsum
  • 9,717
  • 13
  • 63
  • 119
  • Please always use the main language tag for a question. You can optionally use a version-specific tag on top of that, but only if the question is particularly about the difference of that version from other versions. – Kerrek SB Jun 18 '16 at 09:19
  • 1
    There's a thing called "stream orientation", which you can query e.g. with [`std::fwide`](http://en.cppreference.com/w/cpp/io/c/fwide). It's a bit of a mess. – Kerrek SB Jun 18 '16 at 09:21
  • 2
    The answer greatly depends on operating system, the terminal emulator and its settings that you are using, as well as the format of the strings that you are using. If you don't specify the operating system and the precise settings, we cannot give you a precise answer. – CinchBlue Jun 18 '16 at 09:33

0 Answers0