加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c wcout std :: map value

发布时间:2020-12-16 06:57:50 所属栏目:百科 来源:网络整理
导读:我有一个名为’prompts’的std :: map,声明如下: std::mapconst int,wstring,std::lessint,std::allocatorstd::pairconst int,std::wstring prompts; 它存储int’key’和wstring’value’对.如果我这样做: wcout prompts[interpreter-get_state()]; 编译器
我有一个名为’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打印?某种演员?要么…?

解决方法

在第一行,你缺少一个std ::

std :: map< const int,std :: wstring,std :: less< int&gt ;,std :: allocator< std :: pair< const int,std :: wstring> >>提示;

你应该写std :: wcout而不是wcout.

我只是尝试了这个代码,它编译.

#include <map>
#include <iostream>
#include <string>

int main()
{
    std::map<const int,std::wstring,std::wstring> >> prompts;
    std::wcout << prompts[1];
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读