473,757 Members | 10,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Support for std::wstring

Hi all,
can somebody tell how much std::wstring is supported across
different compilers on different platforms? AFAIK std::string is
supported by almost all C++ compilers and almost all platforms, is that
also the case with wstring?

Another related question that I have is, is it advisable to use
wstring than string for unicode support? To be able to support Unicode
build, is it that all the occurrence of std::string will need to be
changed to std::wstring?

Ps: I am little new to unicode stuff so please elaborate or point me to
external links for reference if need be. Not sure that if it is the
right forum to post this question but I guess it is related.

Thanks,
Divick

Jul 6 '06 #1
8 16482

Divick wrote:
Hi all,
can somebody tell how much std::wstring is supported across
different compilers on different platforms? AFAIK std::string is
supported by almost all C++ compilers and almost all platforms, is that
also the case with wstring?
Yes - all conforming compilers will support std::wstring. I doubt you
can find a compiler that supports std::string but not std::wstring.
>
Another related question that I have is, is it advisable to use
wstring than string for unicode support? To be able to support Unicode
build, is it that all the occurrence of std::string will need to be
changed to std::wstring?
Hold on. std::wstring is not necesarrily unicode. On windows it will
likely be the unicode-subset also used by Java, but there are now
guarantees.
>
Ps: I am little new to unicode stuff so please elaborate or point me to
external links for reference if need be. Not sure that if it is the
right forum to post this question but I guess it is related.
A google for unicode should take you the official unicode page with a
minimum of effort.
>
Thanks,
Divick
/Peter

Jul 6 '06 #2
peter koch <pe************ ***@gmail.comwr ote:
Yes - all conforming compilers will support std::wstring. I doubt you
can find a compiler that supports std::string but not std::wstring.
libstdc++ port for Windows (as bundled with mingw compiler) does not
support std::wstring, because its implementation is dependent on
POSIX-style locale. But one can always use STLPort, which does support
std::wstring with this compiler.
> Another related question that I have is, is it advisable to use
wstring than string for unicode support? To be able to support
Unicode build, is it that all the occurrence of std::string will
need to be changed to std::wstring?
Hold on. std::wstring is not necesarrily unicode.
indeed, but on platforms that directly support Unicode on the operating
system level, wchar_t usually is some Unicode encoding (on Windows 2000
or newer it's UTF-16). I'd say that it's OK to use std::wstring and
wchar_t to handle Unicode strings if both are true:
- you do not care which encoding is used
- you do not target exotic platforms where wchar_t is not Unicode at all
B.

Jul 6 '06 #3
Divick wrote:
Hi all,
can somebody tell how much std::wstring is supported across
different compilers on different platforms? AFAIK std::string is
supported by almost all C++ compilers and almost all platforms, is that
also the case with wstring?
IIRC the old gcc 2.95 shipped with a pre-standard STL that didn't
support wide strings (among other irregularities) . I had to write code
for that as recently as 2 years ago, and although I ended up upgrading
its libraries to STLport, wchar_t support was so broken on that platform
(an old SCO Unix from early or mid 90-ies) that STLport had to be
configured without wchar_t support, hence no std::wstring.

>
Another related question that I have is, is it advisable to use
wstring than string for unicode support? To be able to support Unicode
build, is it that all the occurrence of std::string will need to be
changed to std::wstring?
Yes; plus you may have to convert to/from something like UTF-8 when
interfacing with some libraries (like system functions that expect
filenames in UNIX and their C++ "equivalent s", like std::fstream::o pen).
You can't really get rid of *all* "narrow" strings completely most of
the time, you'll end up with code that uses both types depending on the
situation. I've found this to be too painful in practice most of the
time. The alternative is to store UNICODE strings encoded in char-based
strings with a variable-length encoding supported on your system (UTF-8,
usually). Of course in this case your strings will be "non-linear" (no
simple mapping between byte/UNICODE char offsets), some bit patterns are
forbidden, etc, so it may not be sufficient for what you need.

D.
Jul 6 '06 #4
Davlet Panech wrote:
Yes; plus you may have to convert to/from something like UTF-8 when
interfacing with some libraries (like system functions that expect
filenames in UNIX and their C++ "equivalent s", like std::fstream::o pen).
You can't really get rid of *all* "narrow" strings completely most of
the time, you'll end up with code that uses both types depending on the
situation. I've found this to be too painful in practice most of the
time. The alternative is to store UNICODE strings encoded in char-based
strings with a variable-length encoding supported on your system (UTF-8,
usually). Of course in this case your strings will be "non-linear" (no
simple mapping between byte/UNICODE char offsets), some bit patterns are
forbidden, etc, so it may not be sufficient for what you need.

D.
Just to clarify: I'm not saying you shouldn't use wchar's just that
you'll probably have to use encoded (UTF-8) forms regardless especially
on UNIX-like systems. In my experience it's easier to convert to/from
wchar's *only* when necessary, rather than blindly throughout.

D.
Jul 6 '06 #5

Divick wrote:
Another related question that I have is, is it advisable to use
wstring than string for unicode support? To be able to support Unicode
build, is it that all the occurrence of std::string will need to be
changed to std::wstring?
It's actually a fantastically complicated area. The standard string
implementations are not designed for handling multi-character encodings
- this means that they're not designed for UTF-8 in 8 bit char derived
std::string and nor are they designed for UTF-16 in 16 bit wchar_t
derived std::wstring. The only safe way is to create your own char
traits to use 32 bit integers in std::basic_stri ng<and then convert
to UTF-16 and UTF-8 as needed.

Having said that though, you can use std::string and std::wstring
(assuming char is 8 bit and wchar_t is 16 bit) so long as you're
careful. Remember that length() will return the number of UTF-8 or
UTF-16 encoded characters and that functions like substr() are liable
to chop within a single code point as a single Unicode code point can
be up to four UTF-8 chars and two UTF-16 wchar_ts.

You can get around some of this if you write your own string iterators
and use those, but by then you may as well write your own string
classes that do handle them correctly. If you don't do any string
manipulation then you'll probably be ok.

By the time you understand the encodings well enough to know which
string manipulations are safe and which aren't you won't need to ask
here about them :-)
K

Jul 7 '06 #6
Hi all,
That definitely helps. I think I need to look more into unicode
stuff from a programming perspective to understand more of what all you
guys are saying.

Thanks for all the help,
Divick
Kirit Sælensminde wrote:
Divick wrote:
Another related question that I have is, is it advisable to use
wstring than string for unicode support? To be able to support Unicode
build, is it that all the occurrence of std::string will need to be
changed to std::wstring?

It's actually a fantastically complicated area. The standard string
implementations are not designed for handling multi-character encodings
- this means that they're not designed for UTF-8 in 8 bit char derived
std::string and nor are they designed for UTF-16 in 16 bit wchar_t
derived std::wstring. The only safe way is to create your own char
traits to use 32 bit integers in std::basic_stri ng<and then convert
to UTF-16 and UTF-8 as needed.

Having said that though, you can use std::string and std::wstring
(assuming char is 8 bit and wchar_t is 16 bit) so long as you're
careful. Remember that length() will return the number of UTF-8 or
UTF-16 encoded characters and that functions like substr() are liable
to chop within a single code point as a single Unicode code point can
be up to four UTF-8 chars and two UTF-16 wchar_ts.

You can get around some of this if you write your own string iterators
and use those, but by then you may as well write your own string
classes that do handle them correctly. If you don't do any string
manipulation then you'll probably be ok.

By the time you understand the encodings well enough to know which
string manipulations are safe and which aren't you won't need to ask
here about them :-)
K
Jul 7 '06 #7

Bronek Kozicki skrev:
peter koch <pe************ ***@gmail.comwr ote:
Yes - all conforming compilers will support std::wstring. I doubt you
can find a compiler that supports std::string but not std::wstring.

libstdc++ port for Windows (as bundled with mingw compiler) does not
support std::wstring, because its implementation is dependent on
POSIX-style locale. But one can always use STLPort, which does support
std::wstring with this compiler.
I forgot that - thanks for reminding me.
>
Another related question that I have is, is it advisable to use
wstring than string for unicode support? To be able to support
Unicode build, is it that all the occurrence of std::string will
need to be changed to std::wstring?
Hold on. std::wstring is not necesarrily unicode.

indeed, but on platforms that directly support Unicode on the operating
system level, wchar_t usually is some Unicode encoding (on Windows 2000
or newer it's UTF-16). I'd say that it's OK to use std::wstring and
wchar_t to handle Unicode strings if both are true:
- you do not care which encoding is used
- you do not target exotic platforms where wchar_t is not Unicode at all
I part of agree here. You can not use std::wstring as a generic unicode
string in Windows as the representation is encoded using the same
principle as for utf-8. Thus, s[i] might not necesarrily return the
i'th character of s. If you are aware of this (or only process
characters in the basic plane), you are safe.

/Peter
>

B.
Jul 7 '06 #8
Divick wrote:
Hi all,
That definitely helps. I think I need to look more into
unicode stuff from a programming perspective to understand more of
what all you guys are saying.
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the newsgroup FAQ entry:

<http://www.parashift.c om/c++-faq-lite/how-to-post.html#faq-5.4>


Brian
Jul 7 '06 #9

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

Similar topics

1
12280
by: red floyd | last post by:
I have a an app that I'm writing which uses char and std::string. I'm using a library which expects wchar_t arrays. Is there a standard way to convert between std::string and std::wstring, or do I need to use something like std::transform()? Thanks
4
10185
by: sorty | last post by:
Hi, I have read in many places that TCHAR can be 'char' or 'wchar_t' depending on ANSI or UNICODE. I have also read that LPTSTR is a long pointer to a TCHAR. I am confused about the following. Please answer with yes/no and then elaborate as you please..
0
2145
by: Shankar | last post by:
Hello, I have a C++ dll with one class which has one public function. This function returns an std::list<std::wstring> as an argout. I am using SWIG to generate Python extensions for this dll. I have the following code in python to access the string from the list. .. ..
3
5858
by: uday.sen | last post by:
Hi, I am porting a piece of code from VC++ to linux platform. My compiler is g++ 3.2.2. I am getting following error: no matching function for call to A::setResponse(std::wstring) candidates are A::setResponse(std::wstring &) ---> This is indeed the signature I am using this function as:
14
12194
by: rohitpatel9999 | last post by:
Hi While developing any software, developer need to think about it's possible enhancement for international usage and considering UNICODE. I have read many nice articles/items in advanced C++ books (Effective C++, More Effective C++, Exceptional C++, More Exceptional C++, C++ FAQs, Addison Wesley 2nd Edition) Authors of these books have not considered UNICODE. So many of their
4
4430
by: Howie Meier | last post by:
Hallo NG, i can call functions from a native C++-dll wich uses "const char *" as stringtype via P/Invoke without problems. Is there an easy way to call functions that uses std::string or std:wstring in the function call ? Has someone a tiny example how to access such a DLL with an IJW-Interface ?
10
10135
by: Jeffrey Walton | last post by:
Hi All, I've done a little homework (I've read responses to similar from P.J. Plauger and Dietmar Kuehl), and wanted to verify with the Group. Below is what I am performing (Stroustrup's Appendix D recommendation won't compile in Microsoft VC++ 6.0). My question is in reference to MultiByte Character Sets. Will this code perform as expected? I understand every problem has a simple and elegant solution that is wrong.
1
9322
by: sandeepkavade | last post by:
hi all i want to convert wstrint to WCHAR* how to do that? i am getting following error: error C2664: 'UnicodeToUtf8' : cannot convert parameter 1 from 'std::wstring *__w64 ' to 'const WCHAR *'
10
8271
bajajv
by: bajajv | last post by:
Hi, I was trying to implement CString with std::string and std::wstring. class CString { public: std::string str; CString() {str = "ABCD";} //this works }: class CString {
0
9489
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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
9737
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...
0
8737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
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
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.