Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Extended ASCII characters in console app (http://www.velocityreviews.com/forums/t279038-extended-ascii-characters-in-console-app.html)

Bob Hartung 11-07-2003 10:00 PM

Extended ASCII characters in console app
 
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! ]

Thomas Matthews 11-08-2003 01:21 PM

Re: Extended ASCII characters in console app
 
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! ]

Mike Wahler 11-08-2003 01:22 PM

Re: Extended ASCII characters in console app
 

"Bob Hartung" <rwhart@netexpress.net> wrote in message
news:bof4os$kuc@library2.airnews.net...
> 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! ]

Louie van Bommel 11-08-2003 01:34 PM

Re: Extended ASCII characters in console app
 

Bob Hartung <rwhart@netexpress.net> wrote in article
<bof4os$kuc@library2.airnews.net>...
> 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! ]

Thomas Matthews 11-09-2003 11:23 AM

Re: Extended ASCII characters in console app
 
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! ]

shan23 05-28-2009 12:04 PM

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


All times are GMT. The time now is 05:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.