生活随笔
收集整理的這篇文章主要介紹了
C++ 遍历map
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <iostream>
#include <map>
using namespace std;int main()
{std::map<string, string> mapName;mapName["張三"] = "19";mapName["李四"] = "18";mapName["王二"] = "17";map<string, string>::iterator iter;// while 循環iter = mapName.begin();while (iter != mapName.end()){cout << iter->first << " " << iter->second << endl;iter++;}// for 循環for (iter = mapName.begin(); iter != mapName.end(); iter++){cout << iter->first << " " << iter->second << endl;}// for 循環for (auto &it : mapName){cout << it.first << " " << it.second << endl;}return 0;
}
總結
以上是生活随笔為你收集整理的C++ 遍历map的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。