none
Win32 console application and non latin characters

    Question

  • I am trying to get the following code to work:

    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	wcout << L"\"áíóöðþýúé\"";
    	return 0;
    }

    When I run the program I get the following output: "ßݾ÷■²·Ú"

    I want it to output a string with non latin characters as I type it in the source code but it always outputs some other non latin characters then I intended it to.

    I would rather not have to use some escape sequences to output the characters.

    • Edited by Atler Sunday, July 04, 2010 9:36 PM
    Sunday, July 04, 2010 8:45 PM

Answers

  • Atler wrote:
    >
    >I can get it to print non latin charachters only not the right ones. I need
    >to do this in unmanaged code. I think the problem lies in what character set
    >the compiler uses.
     
    The compiler does not use any 8-bit character set at all. Your editor has
    created those characters using some character set (which the compiler does
    not know), and your console displays characters using some character set
    (which the compiler does not know).
     
    There is simply no save way to embed extended 8-bit characters in C code.
    You either need to use Unicode, or use escape code in a format that matches
    the code page that will be in place when your program runs.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, DDK MVP
    • Proposed as answer by Yi Feng LiModerator Friday, July 09, 2010 4:37 AM
    • Marked as answer by Atler Sunday, July 11, 2010 8:32 PM
    Sunday, July 04, 2010 10:44 PM
  • Your C code uses code page 1252 (ANSI), the console uses 437 (OEM).
    You should never hard-code strings in code, this is why resources are for.


    -- Mihai Nita [Microsoft MVP, Visual C++]
    http://www.mihai-nita.net
    ------------------------------------------
    Replace year with _ to get the real email

    • Marked as answer by Atler Sunday, July 11, 2010 8:33 PM
    Monday, July 05, 2010 9:25 AM

All replies

  • Atler wrote:

    Win32 console application and non latin characters

    http://blogs.msdn.com/b/michkap/archive/2010/04/07/9989346.aspx


    Igor Tandetnik

    Sunday, July 04, 2010 9:06 PM
  • Atler wrote:

    Win32 console application and non latin characters

    http://blogs.msdn.com/b/michkap/archive/2010/04/07/9989346.aspx


    Igor Tandetnik


    I can get it to print non latin charachters only not the right ones. I need to do this in unmanaged code. I think the problem lies in what character set the compiler uses.

    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main(){
    string x;
    getline(x, cin);
    cout << x;
    }

    If I enter áíóöðþýúé it prints out áíóöðþýúé. Some CLR functions like

    Console::WriteLine(L"áíóöðþýúé");

    do it fine. So i think it might be a setting in Visual Studio or somthing.

     

    Sunday, July 04, 2010 9:33 PM
  • Atler wrote:
    >
    >I can get it to print non latin charachters only not the right ones. I need
    >to do this in unmanaged code. I think the problem lies in what character set
    >the compiler uses.
     
    The compiler does not use any 8-bit character set at all. Your editor has
    created those characters using some character set (which the compiler does
    not know), and your console displays characters using some character set
    (which the compiler does not know).
     
    There is simply no save way to embed extended 8-bit characters in C code.
    You either need to use Unicode, or use escape code in a format that matches
    the code page that will be in place when your program runs.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, DDK MVP
    • Proposed as answer by Yi Feng LiModerator Friday, July 09, 2010 4:37 AM
    • Marked as answer by Atler Sunday, July 11, 2010 8:32 PM
    Sunday, July 04, 2010 10:44 PM
  • Your C code uses code page 1252 (ANSI), the console uses 437 (OEM).
    You should never hard-code strings in code, this is why resources are for.


    -- Mihai Nita [Microsoft MVP, Visual C++]
    http://www.mihai-nita.net
    ------------------------------------------
    Replace year with _ to get the real email

    • Marked as answer by Atler Sunday, July 11, 2010 8:33 PM
    Monday, July 05, 2010 9:25 AM