不用迭代器的容器表示

来源:互联网 发布:赛奇排名优化查询工具 编辑:程序博客网 时间:2024/05/21 02:50
/*[方式一] 结构体放栈中,vector中放副本---------------------*/#include <iostream>#include <string>#include <vector>typedef struct student{   char school_name[100];   char gender;   int age;   bool is_absent;} StudentInfo; typedef std::vector<StudentInfo> StudentInfoVec;void print(StudentInfoVec* stduentinfovec){   for (int j=0;j<(*stduentinfovec).size();j++)    {       std::cout<<           (*stduentinfovec)[j].school_name<<"\t"<<           (*stduentinfovec)[j].gender<<"\t"<<           (*stduentinfovec)[j].age<<"\t"<<           (*stduentinfovec)[j].is_absent<<"\t"<<std::endl;    }   return;} int main(){   StudentInfo micheal={"Micheal",'m',18,false};   StudentInfo cherry={"Cherry",'f',16,true};   StudentInfoVec studentinfovec;   studentinfovec.push_back(micheal);   studentinfovec.push_back(cherry);   print(&studentinfovec);   return 0;}

0 0
原创粉丝点击