wchar_t* 到字符串的转换

2022-01-13 00:00:00 string winapi type-conversion c++ wchar-t

如何在 win32 控制台中将 wchar_t* 数组转换为 std::string varStr.

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

推荐答案

使用wstring,看这段代码:

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;

相关文章