How to use wide char

R

Raghu

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
 
A

Alf P. Steinbach

* Raghu:
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?

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).
 
T

TB

Raghu sade:
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top