关于C++中的map的遍历,使用下面代码:
#include "mainwindow.h"
#include <QApplication>
#include <iostream>
#include <map>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// MainWindow w;
// w.show();
map<int,string> ss;
ss[0] = "nihao";
ss[1] = "hello";
ss[2] = "cpp";
map<int,string>::iterator it;
for(it = ss.begin(); it != ss.end(); it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
return a.exec();
}
打印出来: