string class that can convert between wchar_t and char

B

Bren

Hi all,

I wonder if anyone knows of a string class out there that can do on
demand conversion from wchar_t to char?

We are writing an app that will need to be localized and cross
platform. At this point we are going with Unicode and wchar_t arrays.
I am considering using the string class.

We also use a lot of third party libraries, most of which prefer
ordinary char arrays.

I am hoping to find a class or macro that can do in-place conversion
of wchar_t to char arrays, ideally something similar to the MS W2A/A2W
macros. A string class that could accept/manage a wchar_t string and
return a char* with a call similar to c_str() would also be great as
well.

We are currently using a function which accepts a char* to an
allocated string and converts a wchar_t string into it, but this
requires code before (to alloc) and after (to free) every call. I'm
hoping for something a little easier to use.

Any suggestions?
 
D

Default User

Bren said:
Hi all,

I wonder if anyone knows of a string class out there that can do on
demand conversion from wchar_t to char?


What is the nature of the conversion?



Brian Rodenborn
 
T

Thomas Wintschel

Bren said:
Hi all,

I wonder if anyone knows of a string class out there that can do on
demand conversion from wchar_t to char?

We are writing an app that will need to be localized and cross
platform. At this point we are going with Unicode and wchar_t arrays.
I am considering using the string class.

We also use a lot of third party libraries, most of which prefer
ordinary char arrays.

I am hoping to find a class or macro that can do in-place conversion
of wchar_t to char arrays, ideally something similar to the MS W2A/A2W
macros. A string class that could accept/manage a wchar_t string and
return a char* with a call similar to c_str() would also be great as
well.

We are currently using a function which accepts a char* to an
allocated string and converts a wchar_t string into it, but this
requires code before (to alloc) and after (to free) every call. I'm
hoping for something a little easier to use.

Any suggestions?

This is off-topic and should be asked in a windows newsgroup but...

Try _bstr_t in the ATL package (include comutil.h (or comdef.h)).

Tom
 
P

Peter van Merkerk

I wonder if anyone knows of a string class out there that can do on
Ummmmm, convert a string from wchar_t to char, and/or back?

Not every possible wchar_t value can be represented by a char, hence
some conversion needs to take place. Depending on your requirements the
wchar_t to char conversion could be as simple as stripping the higher
order bits or as complicated as converting to an encoding that uses
escape codes to represent certain characters.
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top