c ++ wcout std :: map value

时间:2011-10-30 02:01:23

标签: map c++

我有一个名为'prompts'的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)

我需要做些什么才能从地图返回的wstring值用wcout打印?某种演员?还是...?

1 个答案:

答案 0 :(得分:1)

在第一行中,您遗漏了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;
}