本文共 1104 字,大约阅读时间需要 3 分钟。
#include #include using namespace std;struct Triple{ int color [3];};struct student{ string name; int age;};int main(){ /* Array as a map's value */ Triple red = {1, 0, 0}, green = {0, 1, 0}, blue = {0, 0, 1}; std::map colors; colors.insert(std::pair (0, red)); colors.insert(std::pair (1, green)); colors.insert(std::pair (2, blue)); map ::iterator it; for(it = colors.begin(); it != colors.end(); it++) { printf("%d --- %d\n", it->first, it->second.color[0]); } student st1 = {"muahao", 20}; student st2 = {"jack", 21}; map mp; mp.insert(pair (0, st1)); mp.insert(pair (1, st2)); map ::iterator it2; for (it2 = mp.begin(); it2 != mp.end(); it2++) { printf("%d-----age:%d \n", it2->first, it2->second.age); cout << "name:" << it2->second.name << endl; } return 0;}
#./v30 --- 11 --- 02 --- 00-----age:20name:muahao1-----age:21name:jack
转载于:https://www.cnblogs.com/muahao/p/8831948.html