473,395 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

unicode characters in c++

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

Nov 30 '06 #1
5 11667

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"ěščřžýá*éǼΨЊتةبאָ*ﻏﺙﺵ\x1 A6F";

Just remember, that you need to have source file encoded with correct
encoding.
Nov 30 '06 #2

Ondra Holub wrote:
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"ěščřžýá*éǼΨЊتةبאָ*ﻏﺙﺵ\x1 A6F";

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

Nov 30 '06 #3

Josh napsal:
Ondra Holub wrote:
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"ěščřžýá*éǼΨЊتةبאָ*ﻏﺙﺵ\x1 A6F";

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
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

Nov 30 '06 #4
Ondra Holub schreef:
Josh napsal:
>Ondra Holub wrote:
>>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"ěščřžýá*éǼΨЊتةبאָ*ﻏﺙﺵ\x1 A6F";

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

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
Nov 30 '06 #5
Josh wrote:
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/
Nov 30 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Hallvard B Furuseth | last post by:
Has someone got a Python routine or module which converts Unicode strings to lowercase (or uppercase)? What I actually need to do is to compare a number of strings in a case-insensitive manner,...
48
by: Zenobia | last post by:
Recently I was editing a document in GoLive 6. I like GoLive because it has some nice features such as: * rewrite source code * check syntax * global search & replace (through several files at...
4
by: Basil | last post by:
Hello. I have compiler BC Builder 6.0. I have an example: #include <strstrea.h> int main () { wchar_t ff = {' s','d ', 'f', 'g', 't'};
7
by: Michael Davis | last post by:
Hi, I've known C/C++ for years, but only ever used ascii strings. I have a client who wants to know how gcc handles unicode. I've found the functions utf8_mbtowc, utf8_mbstowcs, utf8_wctomb and...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
14
by: abhi147 | last post by:
Hi , I want to convert an array of bytes like : {79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3} into Unicode character with ISO-8859-1 standard. Can anyone help me .. how should...
8
by: Preben Randhol | last post by:
Hi If I use len() on a string containing unicode letters I get the number of bytes the string uses. This means that len() can report size 6 when the unicode string only contains 3 characters...
7
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
8
by: mario | last post by:
I have checks in code, to ensure a decode/encode cycle returns the original string. Given no UnicodeErrors, are there any cases for the following not to be True? unicode(s, enc).encode(enc)...
8
by: miztaken | last post by:
Hi, I have a string with some unicode characters and when i tried to displayed it in TreeView its not displaying. I am doing like this: TreeNode tn = new TreeNode("unicodestring");...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.