I was making a simple console program that generates two random 2-D Vectors, Adds them, subtracts them and gives the output in the the Unit-Vector firm as well as Magnitude form with Angle from the Co-ordinate Axes.
Now what I was interested to know was this:
Is there a way to output a special character (That is not in the ASCII list)
like î?
I am using Windows 7 if it matters.
EDIT:
I noticed that the character I used was not visible so clearly.
The character is i cap (like in 5î).
Usually when I output things to the console that fail the isprint(thechar) I end up outputting something like this cout << '[' << (int)((unsignedchar)thechar) << ']';
The Windows console has a "code page" associated with it, which defaults to the old "Extended ASCII" set you see from DOS days. You can change the code page and then print stuff like that.
The Windows console can also display Unicode stuff if you output it in UTF-16LE. (Use a BOM.)
To write UNICODE chars (assuming LE is the standard Windows variant of UTF-16...) out with the iostream library, call _setmode() with _O_U16TEXT and then use wcout.
Note that cout doesn't work when this mode is set (well, I hit asserts...)
Also note that the console CP and the CRT CP are handled separately.
P.P.S. If you want to get European accented ANSI chars to behave on an English version Windows, when using a console app, the following trick might be of use. I use it for little test tools for a bilingual program -- French/English -- when testing on an English system. It uses CharToOem() to work its magic.
If you use std::cin to read input you require the reverse mapping.
Also note that when this mechanism is operational, the strings written to file are confused. So you need it on to write to the console, but off to write to file. A bit of a pain...
I've successfully used wcout to write UNICODE strings to the console for wstrings containing standard European chars, and box drawing chars, to the console using _setmode. In this case I would expect narrow() to do nothing.
When you say "see narrow()... do you mean see the documentation? Or see the source code?)
Er, what do you mean? How does _setmode() affect it? Are you saying that the console stream needs to be in binary mode to work?
Also, did you actually output non-C0/C1 characters to the console, or did you output something with a code wider than eight bits?
The STL wide streams simply chop the input wchar_t to an eight-bit char before outputting to a char stream. (I think you have to install a special locale to prevent that, or somesuch, but that is, IIRC, more difficult than it should be, especially when working with multiple compilers/STL libraries/versions.)
P.S. I am genuinely interested in this issue. I am working on a mini project that currently uses Latin-1; we're avoiding Windows-1252 so we are totally safe on Windows, Linux, and Mac OS-X (are we being over neurotic?). But we are considering moving to UTF-8, which only Windows is awkward about (at least in earlier version). Or possibly UTF-16.
Again sorry for not replying. I had been out out of station for the last couple of days...
Well to the wcout now.
I had included <iostream> in another header that was included in the main program. Can't imagine why it wouldn't work, but Re-Including it did the work.
Now another problem.
If I am declaring a variable like this: wchar_t icap = 'î';
and then using wcout, I print icap.
It prints ?.
Am I doing something wrong in declaring it?