How to convert wide character strings to multi-byte strings ?

Hello What is the right way to convert from wide character strings to multi-byte strings ? In boost or in C++ if any ? For narrow to wide conversion I can do wostringstream streamMsg; streamMsg << "Narrow string"; wstring wstrMessage = streamMsg.str(); But I think that too is not a good way as it might not take the current locale / code page /encoding /whatever into account, but just widen the char (as a number) to an wchar_t. So what is the right way ? How do I write a codecvt facet for the default locale if I need one ? Thank you, Timothy Madden

Consider the utf-8 concvt facet. It's documented as part of the serialization library. Robert Ramey Timothy Madden wrote:
Hello
What is the right way to convert from wide character strings to multi-byte strings ? In boost or in C++ if any ?
For narrow to wide conversion I can do
wostringstream streamMsg;
streamMsg << "Narrow string";
wstring wstrMessage = streamMsg.str();
But I think that too is not a good way as it might not take the current locale / code page /encoding /whatever into account, but just widen the char (as a number) to an wchar_t.
So what is the right way ? How do I write a codecvt facet for the default locale if I need one ?
Thank you, Timothy Madden

Timothy Madden wrote:
Hello
What is the right way to convert from wide character strings to multi-byte strings ? In boost or in C++ if any ?
For narrow to wide conversion I can do
wostringstream streamMsg;
streamMsg << "Narrow string";
wstring wstrMessage = streamMsg.str();
But I think that too is not a good way as it might not take the current locale / code page /encoding /whatever into account, but just widen the char (as a number) to an wchar_t.
So what is the right way ? How do I write a codecvt facet for the default locale if I need one ?
Thank you, Timothy Madden
As an aside, couldn't you simply do something like this for your narrow to wide conversion? std::string narrow = "Narrow string"; std::wstring wstrMessage( narrow.begin(), narrow.end() );

On Tue, 02 Feb 2010 20:02:10 +0100, Timothy Madden
What is the right way to convert from wide character strings to multi-byte strings ? In boost or in C++ if any ?
mbstowcs() and wcstombs() in
[...]
participants (4)
-
Boris Schaeling
-
Kenny Riddile
-
Robert Ramey
-
Timothy Madden