我有一个名为“提示”的 std::map,声明如下:
std::map<const int, wstring, std::less<int>, std::allocator<std::pair<const int, std::wstring> >> prompts;
它存储 int 'key' 和 wstring 'value' 对。如果我这样做:
wcout << prompts[interpreter->get_state()];
编译器 (vc10) 提示
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)
我必须做什么才能使 map 返回的 wstring 值用 wcout 打印?某种类型转换?或者……?
最佳答案
在第一行中,您缺少一个 std::
std::map<const int,
std:: wstring, std::less<int>, std::allocator<std::pair<const int, std::wstring> >> prompts;
你应该写std::wcout
而不是 wcout
.
我刚刚试过这段代码,它可以编译。
#include <map>
#include <iostream>
#include <string>
int main()
{
std::map<const int, std::wstring, std::less<int>, std::allocator<std::pair<const int, std::wstring> >> prompts;
std::wcout << prompts[1];
return 0;
}
关于map - C++ wcout std::map 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7942868/