it->second//这是Map容器第二大的数?该怎么解决
it->second//这是Map容器第二大的数???
------解决方案--------------------
map是键值对,first是键,second是值。我觉得楼主还是找本书好好看看
------解决方案--------------------
不能因为second是第二的意思就理解为第二大的数
这里的第二是指每对数值的第二个,就是double,int的第二个,也就是int值了
再因为你的it取的是map的第一个,即std::map<double,int>::iterator it = MapForSort.begin();
所以你的i返回的是第一对数值中的int的那个值 int i = it->second;
即1
std::map<double,int> MapForSort;//借用map来排序
MapForSort[1.0] = 1;
MapForSort[2.0] = 2;
MapForSort[3.0] = 3;
MapForSort[4.0] = 4;
std::map<double,int>::iterator it = MapForSort.begin();
int i = it->second;
------解决方案--------------------
map是键值对,first是键,second是值。我觉得楼主还是找本书好好看看
------解决方案--------------------
不能因为second是第二的意思就理解为第二大的数
这里的第二是指每对数值的第二个,就是double,int的第二个,也就是int值了
再因为你的it取的是map的第一个,即std::map<double,int>::iterator it = MapForSort.begin();
所以你的i返回的是第一对数值中的int的那个值 int i = it->second;
即1