473,506 Members | 17,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string class that can convert between wchar_t and char


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?

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 19 '05 #1
4 10876
Bren wrote:

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
Jul 19 '05 #2
"Bren" <ia***********@sympatico.ca> wrote in message
news:uq********************************@4ax.com...

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
Jul 19 '05 #3
On Fri, 3 Oct 2003 22:12:52 GMT, Default User <fi********@company.com>
wrote:
Bren wrote:

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?


Ummmmm, convert a string from wchar_t to char, and/or back?

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 19 '05 #4
> >> 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?


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.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 19 '05 #5

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

Similar topics

27
51646
by: Trep | last post by:
Hi there! I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003. This is necessary because I...
8
4326
by: Duncan Winn | last post by:
I am new to VC++7. I am using a method GetPrivateProfileString that requires an LPTSTR. I have defined this as a: char * data_name; I am then trying to convert this to an LPOLESTR and I...
15
10796
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
8
3818
by: Frank R Eid | last post by:
Hi all; A) What's the simplest way to convert a 'String' to 'char *' (and the other way araound) ? B) I have some C++ classes that I cannot easily convert to .NET (because they still are...
3
3318
by: Maileen | last post by:
Hi, How can we convert string^ to String or to LPCWSTR ? thx, Maileen
2
5012
by: Alejandro Aleman | last post by:
Hello! i know this may be a newbie question, but i need to convert a string from System::String^ to char*, in the msdn page tells how, but i need to set to /clr:oldSyntax and i dont want it...
4
3470
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
2
6070
by: rachit.goyal | last post by:
Hi All, I am using .net first time.In my windows form VC7 application, on a click of button, I am assigning text of TextBox to STL string varibale. Using this code- private: System::Void...
3
3688
by: Angus | last post by:
I can see how to get a char* but is it possible to get a wide char - eg wchar_t?
0
7105
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
7371
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...
1
7023
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...
0
7479
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...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
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...
0
4702
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...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.