Connecting Tech Pros Worldwide Forums | Help | Site Map

How to use wide char

Raghu
Guest
 
Posts: n/a
#1: Jan 27 '06
Hello all,

I want to know how can we print special characters like ä / ö /etc., on the
console.
I mean, if i want to print a string containing one of these characters
(eg. hällö) how to use wide character data type?

Thanks in advance

Regards
Raghu



Alf P. Steinbach
Guest
 
Posts: n/a
#2: Jan 27 '06

re: How to use wide char


* Raghu:[color=blue]
> Hello all,
>
> I want to know how can we print special characters like ä / ö /etc., on the
> console.
> I mean, if i want to print a string containing one of these characters
> (eg. hällö) how to use wide character data type?
>[/color]

If your compiler supports std::wcout (which g++ for Windows doesn't
currently do) simply use std::wcout instead of std::cout.

At least, that's the theory.

In practice it may not work anyway, because std::wcout performs a
conversion and the end result may not be what your console facility
expects; in that case, you can use platform-specific functionality,
and/or you can try to fiddle with the conversion (never tried it).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
TB
Guest
 
Posts: n/a
#3: Jan 27 '06

re: How to use wide char


Raghu sade:[color=blue]
> Hello all,
>
> I want to know how can we print special characters like ä / ö /etc., on the
> console.
> I mean, if i want to print a string containing one of these characters
> (eg. hällö) how to use wide character data type?
>
> Thanks in advance
>[/color]

You don't need to. Latin-1 codes can be represented using
a normal 'char'. But if your host console uses another
character set (not unicode), then you might get something else,
like if it uses any of windows own abnormal charsets. And if
you're using any of the other Latin-charset, some translation
might also be required, depending on your host environment.

std::cout<<"hällö";

'ä' in both Latin-1 and Unicode has the code number 228.

char aa = 229; // 'ä'
wchar_t waa = 229; // 'ä'

And use an editor that supports unicode or Latin-1.

--
TB @ SWEDEN
Closed Thread