Extended ASCII characters in console app

B

Bob Hartung

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
 
T

Thomas Matthews

Bob said:
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
 
M

Mike Wahler

Bob Hartung said:
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
 
L

Louie van Bommel

Bob Hartung said:
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;
 
T

Thomas Matthews

Bob said:
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
 
Joined
May 28, 2009
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top