CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2007
    Posts
    20

    Lightbulb cout Extended ASCII characters ain't working

    I can't make program print what I want!
    I type this script:

    int main()
    {
    cout << "█▓▒░\n";
    return 0;
    }

    and all I get on console is:

    ????

    How to make program print Extended ASCII characters?

    Please help.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: cout Extended ASCII characters ain't working

    Trying to do block graphics with ascii characters above 07F? What code page is your console using?

  3. #3
    Join Date
    Jul 2007
    Posts
    20

    Unhappy Re: cout Extended ASCII characters ain't working

    Yes. But what do you mean by code page (Can you describe what is code page?)?

    I fought the problem was with preprocessor definitions.

    It was: WIN32;_DEBUG;_CONSOLE

    so I added: _UNICODE (_UNICODE;WIN32;_DEBUG;_CONSOLE)

    and it still weren't working.

    So I played a little and I tried this and it's working?!

    int main()
    {
    char ch = 178;
    int i = 0;
    for ( ; i < 3; ch--, i++)
    {
    cout << ch << endl;
    }
    return 0;
    }

    or similar:

    int main()
    {
    char ch = 178;
    cout << ch << " \n";
    ch--;
    cout << ch << " \n";
    ch--;
    cout << ch << " \n";
    return 0;
    }

    Console result:

    ▓▒░

    So now I am totally confused.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: cout Extended ASCII characters ain't working

    Quote Originally Posted by Vila
    Yes. But what do you mean by code page (Can you describe what is code page?)?
    Do a google search for "code page". It is one of the fundamental things you should be aware of when printing characters that are above ASCII 127. The code page determines what the characters will be between ASCII 128 and ASCII 255.
    So I played a little and I tried this and it's working?!
    So in the current code page, character 178 is one of the block characters you wanted. For another code page, character 178 could be (and probably is) some other character.

    Also, you could have just ran your original program in the debugger, and inspect what the values are of those block characters that you wrote in your program. When you do this, what were the values of those characters?

    Another thing -- don't say "script" when you mean "program". Saying that you wrote a "script" sounds like a total newbie with no comprehension as to what C++ really is.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; July 2nd, 2007 at 10:35 AM.

  5. #5
    Join Date
    Jul 2007
    Posts
    20

    Re: cout Extended ASCII characters ain't working

    Thanks.

    That characters were 176,177,178,219 (it isn't 'some other character').

    And I use wrong code page (1252).

    So will you tell me how to change code page.

    And, just for the record, I know to write 'program' (and by that I mean that I know, well not everything, but enough to write a decent 'program' in C++) in C++, just I newer spoke to anyone about C++, on any forum, so I don't know witch 'terms' are used.

    And I haft to say that I never worked with ASCII characters 128-255 in C++ (and in any other program) so don't be mad at me for not knowing 'one of fundamental things'.

    Thank you again... :|
    Last edited by Vila; July 2nd, 2007 at 12:29 PM.

  6. #6
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: cout Extended ASCII characters ain't working

    Changing the code table for a console window is done by the command GRAFTABL xxx where xxx is code page to use. From code you use SetConsoleCP(UINT wCodePageID)
    Last edited by S_M_A; July 2nd, 2007 at 01:44 PM. Reason: Language

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured