微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c wcout std :: map value

我有一个名为’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;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐