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++ "equivalents", like std::fstream::open).
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.