读书人

调试stl时遇到c2678异常

发布时间: 2012-03-30 17:32:09 作者: rapoo

调试stl时遇到c2678错误
编绎环境:vc6
stl库:stlport
代码:
#include <map>
#include <iostream.h>
#pragma warning(disable: 4786)
typedef std::map <std::string, std::string> CGI_VALUE;
int main()
{
CGI_VALUE cgi;
cgi.insert(CGI_VALUE::value_type( "a ", "aaa "));
const CGI_VALUE _cgi = cgi;

//-----------
CGI_VALUE::const_iterator pos;
for(pos=_cgi.begin(); pos!=_cgi.end(); ++pos)
{
cout < <pos-> first < <endl;
cout < <pos-> second < <endl;
}// ok!
//-----------

cout < < cgi[ "a "] < < endl;//ok!

//-----------
cout < < _cgi[ "a "] < < endl;//error!!!!
}


跪求高手解答案....

[解决办法]
map的const对象不可以调[]。

读书人网 >C++

热点推荐