Prashant Mhatre

Make Money, Programming, Bollywood, Marathi

  • You are here: 
  • Home
  • What is wstring – Discussion on wstring

What is wstring – Discussion on wstring

Posted on March 23rd, 2008

What is wstring – Discussion on wstring


-- Sponsored Links --



-- Sponsored Links --



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?

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.

std::wstring is not necesarrily unicode. On windows it will likely be the unicode-subset also used by Java, but there are now guarantees.

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.

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:

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_string<> 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 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.

Common Questions About wstring

  • wstring to CString conversion : cstring, wstring
  • CString to wstring : wstring, cstring
  • BSTR to wstring : wstring, bstr, convert
  • char ptr to wstring – Urgent! : wstring, char
  • How do I convert wstring variable to LCPWSTR? : convert, wstring …
  • How do I initilize a “vector <wstring> vtws” variable? : vector
  • wide char array to wstring : wstring, char, assign
  • How do I get the Variant result to wstring variable? : messagebox …
  • CopyFile : wchar_t, wstring
  • Loading a File into an array or vector of wstring’s : vector, wstrings
  • Convert from wstring to string? : wstring, string, convert
  • What’s the safe and best way to assing the VARIANT to wstring?
  • std::wstring wont work with overloaded std::operator<< : error …
  • How to convert from wstring to string? : convert, wstring, string
  • How to convert from wstring to string? : convert, wstring, string
  • Writing wstring to text file : wstring, wchar_t
  • wstring(char *Text) constructor ?? or how to handle ? : wstring

Books That talk about wstring

C++ In a Nutshell – Page 672 by Ray Lischner

The string and wstring types are therefore much easier to use and offer greater safety (see the at member function), while still offering ease-of-use with …

C++ Cookbook – Page 468 by D. Ryan Stephens – Computers – 2005 – 592 pages

The exact implementation of wchar_t is implementation defined, but it is often UTF-32. The class wstring, defined in <string>, is a sequence of …

Handbook of Object Technology by Saba Zamir – Computers – 1999 – 1168 pages

There are three main template types: • string and wstring – string and wide-character string types; both bounded string/wstring and unbounded string/wstring …

Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template … - Page 4 by Scott Meyers, Michael Peirce, Hitesh Tewari – Standard template library. (Computer file) – 2001 – 260 pages

Similarly, any time I refer to the relationship between string and char or char*, the same is true of the relationship between wstring and wchar_t or

Wstring Related Searches on Google

basic_string

big5

bjam

bstr

bstr to wstring

c++ wstring

c_str

consulting engineers

convert string wstring

convert wstring

convert wstring to char

convert wstring to string

converting wstring

corba

cout wstring

cstring

cstring to wstring

cygwin

gcc

idl

int to wstring

iostream

istringstream

lpctstr

mingw

msdn

orb

ostringstream

ostrstream

shift jis

sstream

std

std wstring

stl wstring

stlport

string wstring

stringstream

strstream

tce

tcsectorreader

ucs

unicode

utf 8

visual c++

visual studio

widechartomultibyte

wstring

wstring char

wstring to string

Filed under Programming |

Comments are closed.