Thread: question about wchar_t, wcout, charset, unicode

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    88

    question about wchar_t, wcout, charset, unicode

    Code:
    wchar_t test[] = { L"a ö ü" };
    wcout << test << endl;
    The output inside the console is still messed up. The a looks normal, other chars not.

    Can you tell me what to search for to get ride with any (yes any, I mean also chinese) charset and to learn to program cross language?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't believe "wide chars" are supported generically in console mode - you'll have to load the "correct" codepage to make them work.

    For graphical applications, it should work straight away as you've got it written.

    I could be wrong!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Works fine for me, but I'm on Linux.

    The problem is that wcout converts the characters to some other encoding and writes them out. Presumably, it converts them to Windows-1252, which is the most common Windows narrow encoding. But the console uses not the ANSI codepage, but the OEM codepage, which typically is CP437 (I think, US) or CP850 (Europe). Thus, you get garbage.

    So matsp is right. You have to set the console to wide mode in order for it to work. (Well, I hope it works then.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 12:48 AM
  2. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  3. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  4. Should I go to unicode?
    By nickname_changed in forum C++ Programming
    Replies: 10
    Last Post: 10-13-2003, 11:37 AM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM