我有代码:
std::string st = "SomeText";
...
std::cout << st;
Run Code Online (Sandbox Code Playgroud)
这工作得很好.但现在我的团队想要搬到wstring.所以我尝试过:
std::wstring st = "SomeText";
...
std::cout << st;
Run Code Online (Sandbox Code Playgroud)
但这给了我一个编译错误:
错误1错误C2664:'std :: basic_string <_Elem,_Traits,_Ax> :: basic_string(const std :: basic_string <_Elem,_Traits,_Ax>&)':无法将参数1从'const char [8]'转换为'const std :: basic_string <_Elem,_Traits,_Ax>&'D:...\TestModule1.cpp 28 1 TestModule1
在搜索网络后,我读到我应该将其定义为:
std::wstring st = L"SomeText"; // Notice the "L"
...
std::cout << st;
Run Code Online (Sandbox Code Playgroud)
这个编译但打印"0000000000012342"而不是"SomeText".
我究竟做错了什么 ?