c++ 結構體的巢狀使用
阿新 • • 發佈:2019-01-06
//
// Map.hpp
// 練習
//
// Created by hanzhiqiang on 2017/3/23.
// Copyright © 2017年 hanzhiqiang. All rights reserved.
//
#ifndef Map_hpp
#define Map_hpp
#include <iostream>
#include <map>
#include <string>
#include <stdio.h>
usingnamespacestd;
typedefstruct person_info{
int grade;
int level;
}P_INFO;
typedefstruct holmes
{
int posX;
int posY;
P_INFO info;
}HOLMES;
int main()
{
HOLMES h1;
h1.posX = 1;
h1.posY = 1;
h1.info.grade = 1;
h1.info.level = 1;
map<int, HOLMES> m_map;
// m_map[1] = h1;
m_map.insert(pair<int, HOLMES>(2,h1));
map<int, HOLMES
for (it = m_map.begin(); it!=m_map.end(); it++) {
cout<<it->first<<endl;
cout<<it->second.posX<<endl;
cout<<it->second.posY<<endl;
cout<<it->second.info.level<<endl;
}
cout<<"abc"<<endl;
return0;
}
#endif