Extended ASCII characters in console app

Discussion in 'C++' started by Bob Hartung, Nov 7, 2003.

  1. Bob Hartung

    Bob Hartung Guest

    Hi all,
    I need to print the extended character set, the corners,
    vertical bars, crossing bars , etc in a console app.

    I can fudge it with

    #define topT char( 194 ) ;

    then,
    cout topT ;

    but,
    Each output item must be followed by a ; . Is there
    another way. I have looked through 3 texts and come up
    blank on google.

    Any help appreciated. Where to look or perhaps what
    exactly to search on very welcome.

    Thanks

    Bob


    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
     
    Bob Hartung, Nov 7, 2003
    #1
    1. Advertising

  2. Bob Hartung wrote:

    > Hi all,
    > I need to print the extended character set, the corners,
    > vertical bars, crossing bars , etc in a console app.
    >
    > I can fudge it with
    >
    > #define topT char( 194 ) ;
    >
    > then,
    > cout topT ;
    >
    > but,
    > Each output item must be followed by a ; . Is there
    > another way. I have looked through 3 texts and come up
    > blank on google.
    >
    > Any help appreciated. Where to look or perhaps what
    > exactly to search on very welcome.
    >
    > Thanks
    >
    > Bob


    Any character (not wide characters) can be printed using
    the "\xYY" notation, where YY is the hexadecimal notation
    of the value.
    So your example becomes:
    #include <iostream>
    using std::cout;
    int main(void)
    {
    cout << "\xC2";
    return 0;
    }

    You can also embed them in regular text:
    char some_text[] = "What is this '\xC2'?\n";

    If you want to output numbers as characters, then you
    should cast the value before outputting:
    cout << static_cast<char>(194);
    The cast tells the compiler that the value is a character
    not an integer.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book

    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
     
    Thomas Matthews, Nov 8, 2003
    #2
    1. Advertising

  3. Bob Hartung

    Mike Wahler Guest

    "Bob Hartung" <> wrote in message
    news:bof4os$...
    > Hi all,
    > I need to print the extended character set, the corners,
    > vertical bars, crossing bars , etc in a console app.
    >
    > I can fudge it with
    >
    > #define topT char( 194 ) ;


    It's not a good idea to end your macros with a semicolon.

    >
    > then,
    > cout topT ;
    >
    > but,
    > Each output item must be followed by a ;


    The semicolon is a statement terminator. Use it after
    every statement. Do not include it in a macro definition.

    >. Is there
    > another way. I have looked through 3 texts and come up
    > blank on google.


    #define whatsit 194
    /* etc */
    cout << whatsit;

    Actually, I'd prefer to use an actual object instead of a macro:

    const unsigned char whatsit(194);

    /* etc */

    cout << whatsit;

    -Mike


    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
     
    Mike Wahler, Nov 8, 2003
    #3
  4. Bob Hartung <> wrote in article
    <bof4os$>...
    > I need to print the extended character set, the corners,
    > vertical bars, crossing bars , etc in a console app.

    .....
    > Each output item must be followed by a ; . Is there

    Perhaps create a for loop with an integer with values (from say, 128) to
    255.

    A simple C++ cast can convert that integer to a printable char.

    (I'm showing this step for clarity)
    char c = static_cast<char>(i)

    Output this char and the char ';' using cout.

    after the loop is done,
    cout << endl;


    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
     
    Louie van Bommel, Nov 8, 2003
    #4
  5. Bob Hartung wrote:
    > Hi all,
    > I need to print the extended character set, the corners,
    > vertical bars, crossing bars , etc in a console app.
    >
    > I can fudge it with
    >
    > #define topT char( 194 ) ;
    >
    > then,
    > cout topT ;
    >
    > but,
    > Each output item must be followed by a ; . Is there
    > another way. I have looked through 3 texts and come up
    > blank on google.
    >
    > Any help appreciated. Where to look or perhaps what
    > exactly to search on very welcome.
    >
    > Thanks
    >
    > Bob


    Hmm, I thought I already answered this.
    Short and succinct:
    1. cout << '\xC2'; // 0xC2 == 194
    2. cout << static_cast<char>(194);
    3. const char BAR_CHAR = 194;
    cout << BAR_CHAR;
    4. #define BAR_CHAR '\xC2'
    cout << BAR_CHAR; // Equivalent to #1 above.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library

    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
     
    Thomas Matthews, Nov 9, 2003
    #5
  6. Bob Hartung

    shan23

    Joined:
    May 28, 2009
    Messages:
    1
    Problem with solutions posted...

    Hi guys , for some assignment , i needed to print the character 'miu' char(230) .... Unfortunately , I tried all the methods suggested :
    1> cout << static_cast<char>(230) ;
    2> cout << "\xE6" ;

    None of them worked...is it something to do with the OS / compiler i'm using ? (I'm using Linux / gcc 4.2.4 )... Please advise
     
    shan23, May 28, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geoff Warnock
    Replies:
    2
    Views:
    8,028
    Daniel Tryba
    Mar 9, 2005
  2. wob
    Replies:
    4
    Views:
    455
    Dave Thompson
    Aug 1, 2005
  3. Doug Odegaard

    Extended Characters in ASP.NET app

    Doug Odegaard, Apr 30, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    287
  4. James O'Brien
    Replies:
    3
    Views:
    270
    Ben Morrow
    Mar 5, 2004
  5. Alextophi
    Replies:
    8
    Views:
    546
    Alan J. Flavell
    Dec 30, 2005
Loading...

Share This Page