1824976 Members
4010 Online
109678 Solutions
New Discussion юеВ

character encoding

 
SOLVED
Go to solution
CA1497567
New Member

character encoding

As far as I know C++ uses ANSI in order to represent its characters.
How can I read a character in greek, obtain its unicode character and write it again as a string or as a character in console.

I'm desperate with this issue. I have tried with wchar_t but I cannot find the way to use it properly and I cannot write my characteres in a terminal.

Thanks you in advance.

3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: character encoding

Your problem doesn't stem from the language but rather with the display device. You need to understand that all the host computer does is send octets (or groups or octets in the case of wide characters) to the output device (terminal, printer, plotter, ...) and how those octets appear is solely a function of the output device itself.

The typical way this is done is to use curses to select the appropriate alternate character set.
If it ain't broke, I can fix that.
CA1497567
New Member

Re: character encoding

Can you give an example how to use curses, or a link?

Thanks.
Dennis Handly
Acclaimed Contributor

Re: character encoding

First of all, you need to set LANG appropriately. Then try to read and write char strings.

To read a character that's multibyte and convert to unicode, you must use mbtowc(3), or mbstowcs(3) for strings.

To convert that wchar_t string to utf8, you would have to use iconv(3):
cd1 = iconv_open("utf8", "ucs4");
ret = iconv(cd1, &in, &inl, &out, &outl);