1

As I understand c++11 allow easy to use conversion between string and wstring through wstring_convert, and it should be as easy as(incudes are omitted):

int main() {
    std::wstring_convert< std::codecvt_utf8<wchar_t> > converter;
    std::string gg = u8"prova";
    std::wcout << converter.from_bytes(gg.data()) << std::endl;
}

The output is a null string.

I also tried std::codecvt_utf8_utf16 with no luck.

I looked up in stackoverflow and tried many suggestion such as C++ Convert string (or char*) to wstring (or wchar_t*) but nothing appens.

Can anyone help me here?

I'm on windows and I'm using gcc (g++) v 5.3.0 through mingw and msys2.

EDIT: Compiling the same code with Microsoft Visual Studio 2013 results in a working solution.

Community
  • 1
  • 1
marco6
  • 352
  • 2
  • 12

1 Answers1

0

Try this conversion

wstring x(L"xxx");
string str(x.begin(), x.end());
Adam
  • 151
  • 8