#include <iostream>#include <map>#include <string>
int
main
( ) {// 创建一个 map 容器,存储员工的姓名和年龄
std
:: map <std
:: string,
int >employees
;// 插入员工信息
employees
[ "Alice" ] = 30 ;employees
[ "Bob" ] = 25 ;employees
[ "Charlie" ] = 35 ;// 遍历 map 并打印员工信息
for (
std
:: map <std
:: string,
int > :: iteratorit
=employees.
begin ( ) ;it
! =employees.
end ( ) ; ++it
) {std
:: cout <<it
- >first
<< " is " <<it
- >second
<< " years old." <<std
:: endl ;}
return 0 ;
}
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/15225.html