STL map+vector+struct的使用示例

时间:2020-12-15 04:00:45

个人编写的小例子,没有注释,刚毕业时作为技术调研随手编写,仅供参考:

 #include<iostream>
#include<map>
#include<vector> using namespace std; struct date_s
{
long id;
string obj_type;
string obj_name;
};
typedef vector<date_s> S_vector;
int main(int argc,char ** argv)
{
int table_no;
vector<date_s> v_data;
map<int,S_vector> m;
map<int,S_vector>::iterator it_m; date_s d1,d2,d3;
d1.id = ;
d1.obj_name = "lijin";
d1.obj_type = "man"; d2.id = ;
d2.obj_name = "duanxiang";
d2.obj_type = "man"; d3.id = ;
d3.obj_name = "yuandong";
d3.obj_type = "man"; v_data.push_back(d1);
v_data.push_back(d2);
v_data.push_back(d3);
m[] = v_data;
S_vector tmp; it_m = m.begin();
tmp = it_m->second; cout<<it_m->second.front().id<<endl; for(;it_m != m.end();it_m++)
{
// cout<<it_m->first<<":"<<it_m->second.id<<" "<<it_m->second.obj_name<<endl; } return ;
}