黑马201
#include
#include
#include
using namespace std;
void printVector(vector & v)
{
for (vector::iterator it = v.begin(); it != v.end(); it++)
{
cout << *it << " ";
}
}
void test01()
{
vector v1;
for (int i = 0; i < 10; i++)
{
v1.push_back(i);
}
//利用[]的形式来访问
for (int i = 0; i < v1.size(); i++)
{
cout << v1[i] << " ";
}
cout << endl;
//利用at方式访问元素
for (int i = 0; i < v1.size(); i++)
{
cout << v1.at(i) << " ";
}
cout << endl;
//获取第一个元素
cout << "第一个元素:" << v1.front() << endl;
//获取最后一个元素
cout << "第最后一个元素:" << v1.back() << endl;
}
int main()
{
test01();
}