Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Extended ASCII characters in console app

Reply
Thread Tools

Extended ASCII characters in console app

 
 
Bob Hartung
Guest
Posts: n/a
 
      11-07-2003
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! ]
 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      11-08-2003
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! ]
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      11-08-2003

"Bob Hartung" <(E-Mail Removed)> wrote in message
news:bof4os$(E-Mail Removed)...
> 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! ]
 
Reply With Quote
 
Louie van Bommel
Guest
Posts: n/a
 
      11-08-2003

Bob Hartung <(E-Mail Removed)> wrote in article
<bof4os$(E-Mail Removed)>...
> 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, 12 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! ]
 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      11-09-2003
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! ]
 
Reply With Quote
 
shan23 shan23 is offline
Junior Member
Join Date: May 2009
Posts: 1
 
      05-28-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FR/EN] how to convert the characters ASCII(0-255) to ASCII(0-127) Alextophi Perl Misc 8 12-30-2005 10:43 AM
multiple versions of "Extended ASCII characters"(No. 128 to 255) wob C Programming 4 08-01-2005 05:37 AM
Reading and writing extended ascii characters Geoff Warnock Java 2 03-09-2005 11:59 AM
Extended ASCII characters in PIX's remarks. AM Cisco 0 12-30-2004 08:21 AM
routine/module to translate microsoft extended ascii to plain ascii James O'Brien Perl Misc 3 03-05-2004 04:33 PM



Advertisments