// Vectors.cpp : Defines the entry point for the console application.
//vector类称作向量类,它实现了动态的数组,用于元素数量变化的对象数值。像数值一样,vector类也用从0开始的下标表示元素的位置;但
//和数组不同的是,当vector对象创建后,数组的元素个数会随着vector对象元素个数的增大而自动变化
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
using namespace std;
class Student{
public:
string name;
int age;
Student(string n, int a) :name(n), age(a){}
};
ostream & operator<<(ostream &os, const Student &s){
os << s.name << "\t" << s.age;
return os;
}
class StudentManager{
public:
vector<Student> S;
void add(Student&s){
S.push_back(s);
}
//遍历
void display(){
vector<Student>::iterator te = S.begin();
while (te != S.end()){
cout << *te;
cout << endl;
te++;
}
}
void displays(){
for (int i = 0; i < S.size(); i++){
cout << S.at(i);
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
//初始化
Student s1("张三", 19);
Student s2("李四", 20);
Student s3("王五", 22);
Student s4("赵六", 18);
StudentManager sm;
sm.add(s1), sm.add(s2), sm.add(s3), sm.add(s4);
//sm.display();
sm.displays();
return 0;
}