unicode characters in c++

O

Ondra Holub

Josh napsal:
Can anyone tell me how do we use Unicode characters in C++ ????

With prefix L:

wchar_t wch = L'ﺙ';
wchar_t* ws = L"ěšÄřžýáíéǼΨЊتةبאָשּׂï»ïº™ïºµ\x1A6F";

Just remember, that you need to have source file encoded with correct
encoding.
 
J

Josh

Ondra said:
Josh napsal:

With prefix L:

wchar_t wch = L'ﺙ';
wchar_t* ws = L"ěšÄřžýáíéǼΨЊتةبאָשּׂï»ïº™ïºµ\x1A6F";

Just remember, that you need to have source file encoded with correct
encoding.

hi Ondra,
thanx but i have few questions.
will this work for each n every platform???
and do i need to include some extra libraries( header files)???
i want to use unicode specifically in linux environment.
can u plz explain in detail???
thanx again

Josh
 
O

Ondra Holub

Josh napsal:
hi Ondra,
thanx but i have few questions.
will this work for each n every platform???
and do i need to include some extra libraries( header files)???
i want to use unicode specifically in linux environment.
can u plz explain in detail???
thanx again

Josh

Hi Josh.

As far as I know it should work at least on Windows and on Linux. I can
check it on Linux when I will be home (after about 6 hours).

In C++ is wchar_t built-in type, so you do not need to include any
special header (this is valid only for C++, not for C). So far
standard. However for Visual C++ dot NET it is not true, because you
need to #include <cwchar>. Visual studio 2005 compiler works well from
this point of view, gcc has no problem.

You need to have the source file encoded in some encoding, which is
understandable for your compiler. I tried gcc 3.4.4, and it is capable
to compile UTF8-encoded source on UTF8-based SUSE Linux as well as on
Windows. Visual C compiler seems work too.

Ondra
 
C

Capstar

Ondra Holub schreef:
Josh napsal:

Hi Josh.

As far as I know it should work at least on Windows and on Linux. I can
check it on Linux when I will be home (after about 6 hours).

In C++ is wchar_t built-in type, so you do not need to include any
special header (this is valid only for C++, not for C). So far
standard. However for Visual C++ dot NET it is not true, because you
need to #include <cwchar>. Visual studio 2005 compiler works well from
this point of view, gcc has no problem.

You need to have the source file encoded in some encoding, which is
understandable for your compiler. I tried gcc 3.4.4, and it is capable
to compile UTF8-encoded source on UTF8-based SUSE Linux as well as on
Windows. Visual C compiler seems work too.

Ondra

Hi Ondra,

What will be the internal representation of the unicode strings? I'm
pretty sure Windows uses UTF16 internally and wchar_t is 16 bit on
Windows platforms. I also remember reading that Linux uses UTF8 internally.
So would the unicode string in a UTF8 encoded source be translated to
the proper representation for a particular platform during compilation?

Thanks,
Mark
 
A

Amin Kharchi

Josh said:
Can anyone tell me how do we use Unicode characters in C++ ????

Try the widecharacter strings (based on wchar_t).

std::wstring str = L"Special letters: \u00A5 \u00A6 \u00A7";

With \uXXXX you can type in unicode codes. In most cases wchar_t is 16
bit (e.g. on Windows) and means wstrings are in memory UCS2 oder UTF-16.

But it's not easy to convert this to UTF-8 if you try to save this to
disc or send it over a network. There are some classes in the C++
standard library that helps.

But the easiest way is to use the complete ICU by IBM:
http://icu.sourceforge.net/
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top