您的位置:首页 > 其它

不用迭代器的容器表示

2016-03-09 19:57 211 查看
/*[方式一] 结构体放栈中,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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: