2011-10-30 47 views
4

我有所谓的 '提示' 一个std ::地图,声明如下:C++ wcout的std ::地图值

std::map<const int, wstring, std::less<int>, std::allocator<std::pair<const int, std::wstring> >> prompts; 

它存储INT '键' 和wstring的 '价值' 对。如果我这样做:

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) 

我有什么做的就是从地图返回了wcout打印wstring的价值?某种类型的演员?要么...?

回答

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; 
} 
+0

是的,你是对的...我也已经列入代替这是没有帮助或者对我而言....愚蠢的错误。感谢您的帮助... – Mossen

+1

我会责怪语言,而不是你。 – cdiggins