Search code examples
c++stringwinapitype-conversionwchar-t

Conversion of wchar_t* to string


How can I convert an wchar_t* array to an std::string varStr in win32 console.


Solution

  • Use wstring, see this code:

    // Your wchar_t*
    wchar_t* txt = L"Hello World";
    wstring ws(txt);
    // your new String
    string str(ws.begin(), ws.end());
    // Show String
    cout << str << endl;