By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,979 Members | 951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,979 IT Pros & Developers. It's quick & easy.

Extended ASCII characters in console app

P: n/a
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! ]
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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! ]
Jul 19 '05 #2

P: n/a

"Bob Hartung" <rw****@netexpress.net> wrote in message
news:bo********@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! ]
Jul 19 '05 #3

P: n/a

Bob Hartung <rw****@netexpress.net> wrote in article
<bo********@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! ]
Jul 19 '05 #4

P: n/a
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! ]
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.