Output extended ASCII chars

I'm having problems getting extended ASCII cahrs to output from my program...

basically I have:

1
2
3
char corner = 201;
cout << corner << endl; // outputs ╔ as expected
cout << "╔" << endl; // outputs ôòö wtf?? 


Is this a problem with my code?? The compiler\debugger?? The character encoding my IDE uses??

I am using Code::Blocks 8.02 with GCC 3.4.5 (MinGW 3.14) on Windows XP.

Any ideas??
Your text editor is probably not using the MS extended ASCII (what MS now calls OEM) set. I would run your file through od to see if that is the case or not.
My editor lets me select from any number of encodings - which one would be the right one?? WINDOWS-1252 isn't the right one.

Cheers
hi I am capoo....
i compile your program in my compiler(dev c++)
and i get that result

1
2
3
4
char corner = 201;

cout << corner << endl; // outputs ╔ as expected
cout << "╔" << endl; // outputs ?  


i think that the first output is the same at any computer(any processor and compiler...)
but
the second output
the╔ sign my program didn't know it unless i make copy past to it to my program but with no new
i think that sign╔ differ from any program ( compiler ...)
and the other...
i just try to help you ....capoo
Last edited on
Alright... I've never used Unicode on the Win32 console before, but apparently it doesn't play nice with C++.

If you save your files as UTF-8 without the BOM marker g++ will pick up on it just fine.

If you want Unicode output, the cout and wcout streams libraries are not the correct things to use. (There isn't one. Alas.) Both output "narrow" characters. The difference is that wcout narrow()s the wchar_ts it gets whereas cout just barfs on them.

You can write Unicode to the console via the standard streams if you are willing to write your own streambuf class that uses the correct output methods. The trick (whether you write your own streambuf or not) is to use the <windows.h> function WriteConsoleW()
http://msdn.microsoft.com/en-us/library/ms687401(VS.85).aspx

There is one caveat: the Console "Prompt Properties" Font tab must list Lucida Console as the active font.
(If you know what you are doing then you can use others: http://blogs.msdn.com/oldnewthing/archive/2007/05/16/2659903.aspx )

So far I haven't figured out how to set that programmatically yet, but if I do I'll let you know.


For those on Linux you will want to take a read through this:
http://www.cl.cam.ac.uk/~mgk25/unicode.html


What a sticky mess, no? :-(


[edit]
That is all for full Unicode support. If you can find an editor that just uses the MS 437 code page then you can compile and use the "extended ASCII" characters without problem. Read more about CP437 here:
http://en.wikipedia.org/wiki/Code_page_437
Last edited on
Not to beat a dead horse, but I found a nice article about the treacherous caveats to using Unicode in C++
http://www.codeproject.com/KB/stl/upgradingstlappstounicode.aspx?print=true

Now I know why the stupid wcout, etc. streams output chars to stream, instead of wchar_ts.

Good Grief.

[edit]
More stuff:
http://evanjones.ca/unicode-in-c.html
Last edited on
Topic archived. No new replies allowed.