关于关联容器map的疑惑??大家帮帮忙.谢谢.

zzghost 2002-10-17 07:32:38
include<map>
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main()
{
map<string,string> transMap;

typedef map<string,string>::value_type valType;

transMap.insert ( valType ( "gratz", "grateful" ));
transMap.insert ( valType ( "'em", "them" ));
transMap.insert ( valType ( "cuz", "because" ));
transMap.insert ( valType ( "nah", "no" ));
transMap.insert ( valType ( "sez", "says" ));
transMap.insert ( valType ( "tanx","thanks" ));
transMap.insert ( valType ( "wuz", "was" ));
transMap.insert ( valType ( "pos", "suppose" ));

map<string,string>::iterator its = transMap.begin ();
map<string,string>::iterator itsEnd = transMap.end ();

cout << "This is my secret transform" <<endl;

while ( its != itsEnd)
{
cout << "Key: " << (*its).first <<"\t";
cout << "Value: " << (*its).second <<endl;
its ++;
}

cout << endl;
cout << endl;
return 0
}

这是程序的一段.为什么输出的key 和value 是从 "them"到"was"??
而第一个和最后一个都没有输出???
还有是这段程序在vc6.0编译时有百个警告,怎么避免???
help me!!谢谢.
...全文
55 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tigerfox 2002-10-17
  • 打赏
  • 举报
回复
map理论
zzghost 2002-10-17
  • 打赏
  • 举报
回复
是按key排序的?
原来是这样.

我试试.谢谢.
陈硕 2002-10-17
  • 打赏
  • 举报
回复
1. 你数数输出了多少对值,输出是按Key排序的。
2. 编译时 /wd4786 试试?

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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