挂了~挂了~

HelloDan 2007-12-30 01:05:42


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


using std::string;
using std::cout;
using std::endl;
using std::ends;
using std::cin;
using std::multimap;


int main()
{
typedef multimap<string,string>::value_type valType;

multimap<string,string> dic;
dic.insert(valType("OK","Hello"));
dic.insert(valType("OK","World"));
dic.insert(make_pair(string("Good"),string("yours")));
dic.insert(valType("OK","Hello"));

for(multimap<string,string>::iterator iter=dic.begin();iter!=dic.end();++iter)
{
cout<<(*iter).first<<ends<<(*iter).second<<endl;
}


cout<<"\nNow output the equal key words..."<<endl;
multimap<string,string>::const_iterator it=dic.find("OK"); // return the first occurence of the keyword.
multimap<string,string>::size_type cnt=dic.count("OK");
cout<<"count:"<<cnt<<endl;


/*************************************************/
// There is a problem in the following segment
// iterator it here will not stop, why????
for(multimap<string,string>::size_type i=0;i!=cnt;++cnt,++it)
cout<<(*it).first<<ends<<(*it).second<<endl;
/*************************************************/



dic.erase("OK");
cout<<"\nAfer erase operation..."<<endl;
for(multimap<string,string>::iterator iter=dic.begin();iter!=dic.end();++iter)
{
cout<<(*iter).first<<ends<<(*iter).second<<endl;
}

return 0;
}


真不知我上面和程序为什么会挂了~本想在VC6里面调试一下,不过一次我晕,50多个错误。所以来叫大家帮我找了。谢谢了!
并祝大家新年快乐!!!!
...全文
64 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
HelloDan 2007-12-30
  • 打赏
  • 举报
回复
晕了~是这个错误啊。我没认真看,想来想去也想不明白怎样错。谢谢了!!!
晚安!!!
NKLoveRene 2007-12-30
  • 打赏
  • 举报
回复
运行时候出错了
在这句:
for(multimap<string,string>::size_type i=0;i!=cnt;++cnt,++it)
里面的循环++笔误了吧,应该这个:
for(multimap<string,string>::size_type i=0;i!=cnt;++i,++it)

NKLoveRene 2007-12-30
  • 打赏
  • 举报
回复
试了
错误就一个
最后for循环的iter重定义了,新定义一个iter2吧
然后就没错了

64,662

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧