//参考百度百科
#include <map>
#include <string>#include <iostream>
using namespace std;
int main()
{
//map根据键值大小排序
map<int,string> mapStudent;
mapStudent[4] = "student_one";
mapStudent[2] = "student_two";
mapStudent[3] = "student_three";
map<int,string>::iterator iter;
for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
{
cout<<iter->first<<""<<iter->second<<std::endl;
}
getchar();
}
本文详细介绍了如何在C++中利用map数据结构对键进行排序,并通过实例展示了如何将整数作为键,字符串作为值进行映射与遍历。
424

被折叠的 条评论
为什么被折叠?



