Boost logo

Boost Users :

From: Tan, Tom (Shanghai) (TTan_at_[hidden])
Date: 2008-06-18 23:29:18

>I have searched a lot in every place what is the best way to convert a
>string to a wstring (and may be vice versa). But til now I don`t got
>results. Can anyone give me an hint what is the best way to do that
>(also good performance?)? maybe there is something available to do
>may be also with some examples.

Use member function assign().

// wstring ->string
wstring ws(L"this is a wstring");
string s;
s.assign(ws.begin(), ws.end());// now s = "this is a wstring";

// wstring ->string
string s("this is a wstring");
wstring ws;
ws.assign(s.begin(), s.end());// now ws = L"this is a wstring";

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at