c++ wcout std::map value

c++ wcout std::map value

本文关键字:map value std wcout c++      更新时间:2023-10-16

我有一个std::map名为'prompts',声明如下:

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打印?某种石膏?或者…?

在第一行中,您缺少一个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;
}