472,952 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ascii "" and unicode L"" question

mr

How can i 'force' c++ to interprete "blabla" strings as unicode string
instead of ascii string (i just don't want to add 'L' before the thousands
strings that are on my projects...), as all my projects are using unicode,
and i don't see any reason that c++ compilator keep creating ascii

Is it a way?

thanks !
Jul 5 '06 #1
3 10557
* mr:
How can i 'force' c++ to interprete "blabla" strings as unicode string
instead of ascii string (i just don't want to add 'L' before the thousands
strings that are on my projects...), as all my projects are using unicode,
and i don't see any reason that c++ compilator keep creating ascii

Is it a way?
You can not force Unicode in any portable way in C++.

You can change all your string literals to wide string literals by
running a script or C++ program that prepends L to every string literal.

But in addition you need to replace char with wchar_t, std::string with
std::wstring, and so on, and if you have calls to library functions that
expect char-based arguments you'll need to fix those calls to (I suggest
leaving exceptions as char-based because Unicode exceptions have no
advantages that I know of, and many drawbacks).

Also, at least one popular compiler doesn't support std::wcout & family,
so you'll have to use some workaround (this includes a decision about
how to handle i/o).

Good luck: it's a bit of work, but it can pay off.

--
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?
Jul 5 '06 #2

mr wrote:
How can i 'force' c++ to interprete "blabla" strings as unicode string
instead of ascii string (i just don't want to add 'L' before the thousands
strings that are on my projects...), as all my projects are using unicode,
and i don't see any reason that c++ compilator keep creating ascii

Is it a way?

thanks !
I would have to agree with the other poster, adding the L before string
and character literals is the least of your problems, but a good place
to start.

I have already done this for a huge project and it is a lot of work.
You need to examine every single place you use strings and determine
what the correct types are. Some places you must still use narrow
strings (such as network protocols and most file IO). In other places
the format of the wide and narrow strings will depend on other factors
and you will need to write code to narrow and widen strings correctly
taking these factors into account.

To correctly support Unicode is more than just turning on wide
character support though. std::wstring is not able to handle Unicode
strings correctly (not any better than std::string can).

How much work you need to do depends a lot on what the application does
and is one of the reasons why you will need to examine every use of a
string or character (remember for example that wchar_t on most
platforms is not big enough for one Unicode character - you need 32
bits, and that's assuming you can avoid any issues of
canonicalisation).

My tip is to start with all the code that performs IO and then look at
any code that makes use of third party APIs. Thin wrappers for all of
these places are often a good way to handle all of this.

Jul 5 '06 #3
mr posted:
>
How can i 'force' c++ to interprete "blabla" strings as unicode
string instead of ascii string (i just don't want to add 'L' before
the thousands strings that are on my projects...), as all my projects
are using unicode, and i don't see any reason that c++ compilator keep
creating ascii

Is it a way?

What I do is define the following:

#ifdef WIDE
#define LITERAL(x) L##x
#else
#define LITERAL(x) x
#endif
And write code as follows:

SomeFunc( 5, 3, LITERAL("Version 7"), 3 );

--

Frederick Gotham
Jul 5 '06 #4

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

Similar topics

7
by: Barry | last post by:
Hi all, I've noticed a strange error on my website. When I print a capital letter P with a dot above, using & #7766; it appears correctly, but when I use P& #0775 it doesn't. The following...
3
by: Petr Prikryl | last post by:
Hi all, My question is: How do you tackle with mixing Unicode and non-Unicode parts of your application? Context: ======== The PEP 3000 says "Make all strings be Unicode, and have a...
6
by: peter pilsl | last post by:
postgres 7.3.2 I store unicode-data in postgresql. The data is retrieved via webinterfaces, processed with perl and then stored in postgresql (and viceversa). All is going nice with one...
4
by: Ping | last post by:
Hi, All, We can use BitConverter.ToString(byte) to a string, but how to get the byte from a string like "AD-A6-0D-1F"?
1
by: contact.morrison | last post by:
Hello, I'm very new to Python, and unsure how to handle this runtime error below. Pointers in the right direction (RTFM here ... etc) most appreciated. I have an object, called article, that...
8
by: aine_canby | last post by:
>>v = raw_input("Enter: ") Enter: kjjkj Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: 'kjjkj' In my program I need...
5
by: Tony Toews [MVP] | last post by:
I'm very upset with Google's policy of indexing and allowing Google advertising on forum web sites which are "slurping" content from Usenet and Microsoft newsgroup servers. ...
25
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record,...
3
by: Gilles Ganault | last post by:
Hello I'm getting this error while downloading and parsing web pages: ===== title = m.group(1) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 48: ordinal not in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.