/*[方式一] 结构体放栈中,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;
}
不用迭代器的容器表示
最新推荐文章于 2024-05-06 21:32:35 发布