W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
#include <iostream>
#include <map>
using namespace std;
​
int main() {
  map<string, int> people = { {"Bill", 19}, {"Steve", 32}, {"Elon", 26} };
​
  // 使用迭代器遍历映射表
  for (auto it = people.begin(); it != people.end(); ++it) {
      cout << it->first << " 的年龄是: " << it->second << "\n";
  }
  
  return 0;
}