map - C++ wcout std::map 值

标签 map c++

我有一个名为“提示”的 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/

相关文章:

HTML5 Canvas 或 SVG 世界地图

c++ - 将字母转换为整数,然后求字符串之和

c++ - C++ 中的全范围比较运算符?

c++ - 根据 C++ 的规则,它是合法的吗?

c++ - windows下的Qt Application和window Icon

c++ - c++程序的意外输出

c++ - 按值删除 map 元素

map - 如何在 Rascal 中将值类型转换为 Map?

ios5 - MKPointAnnotation : title always visible. 可能吗?

scala - 为什么 HashMap 不是半群,而 Map 是?