473,836 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unicode characters in c++

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

Nov 30 '06 #1
5 11734

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

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

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
25978
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, so I assume it's simplest to convert to lower/upper first. Possibly all strings will be from the latin-1 character set, so I could convert to 8-bit latin-1, map to lowercase, and convert back, but that seems rather cumbersome.
48
4659
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 once) * regular expression search & replace. Normally my documents are encoded with the ISO setting. Recently I was writing an XHTML document. After changing the encoding to UTF-8 I used the
4
3174
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
9011
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 utf8_wcstombs, but I'm wondering if there are any other libraries or functions which can do things like handle different kinds of encodings? Thanks Michael Davis
18
34154
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 Encoding.Convert, but that needs byte arrays. Thanks, /Ger
14
6433
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 I go about doing it ? Thanks
8
20755
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 (that one would write by hand or see on the screen). Is there a way to calculate in characters and not in bytes to represent the characters. The reason for asking is that PyGTK needs number of characters to set the width of Entry widgets to a...
7
4029
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
2415
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) == s mario
8
3204
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"); treeView.Nodes.Add(tn); i can see the unicode characters in DEBUG mode in Visualizers (XLM, HTML and TXT) but i cant see it on TreeView, it gets displayed as
0
9825
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9673
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10859
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10602
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10260
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6984
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4463
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.