#include <algorithm>
void tes01()
{
int arr[]={1,2,3,4};
int *p=arr;
for(int i=0;i<arr.size()-1;i++)
{
cout<<**(p++)<<endl;
}
}
void myPrint(int val)
{
cout << val << endl;
}
void test02()
{
vector<int> v;
v.pushback(10);
v.pushback(20);
vector<int>::iterator itBegin=v.begin();
vector<int>::iterator itEnd=v.end();
while(itBegin != itEnd)
{
cout<<*itBegin<<enl;
}
for(vector<int> iterator it=v.begin();it!=v.end();it++)
{
cout<<*it<<endl;
}
for_each(v.begin(), v.end(), myPrint);
}
class Person
{
public:
Person(string name, int age)
{
this->m_Name = name;
this->m_Age = age;
}
string m_Name;
int m_Age;
};
void test03()
{
vector<Person> v;
Person p1("aaa", 10);
Person p2("bbb", 20);
Person p3("ccc", 30);
Person p4("ddd", 40);
v.push_back(p1);
v.push_back(p2);
v.push_back(p3);
v.push_back(p4);
for (vector<Person>::iterator it = v.begin(); it != v.end();it++)
{
cout << "姓名: " << (*it).m_Name << " 年龄: " << it->m_Age << endl;
}
}