标签:style 头部 front clu span oid highlight blog use
#include<iostream>
using namespace std;
#include"vector"
//输出(放在main函数里面出错 为什么????????)
//因为函数里面不能定义函数!!!
void printV(vector<int> &obj)
{
for (int i = 0; i < obj.size(); i++)
{
cout << obj[i] << " ";
}
cout << endl;
}
int main()
{
vector<int> v1;
v1.push_back(1);
v1.push_back(3);
v1.push_back(5);
cout <<" v1 的大小是: " << v1.size() << endl;
cout << "v1 的 头部元素是 :" << v1.front() << endl;
//更改头尾部元素
v1.front() = 11;
v1.back() = 22;
while (v1.size() != 0)
{
cout << "尾部元素为 : " << v1.back() << " ";
v1.pop_back();//删除尾部元素
}
cout << endl<< " 删除后 v1 的大小是: " << v1.size() << endl;
vector<int>v11 = {1,2,3};
//初始化
vector<int> v2 = v11;
vector <int > v3(v11.begin(), v11.end());
cout << "v2 is :";
printV(v2);
cout << "v3 is :";
printV(v3);
vector<int > a1(10);//这里必须分配数组内存,否则不能进行赋值运算。
for (int i = 0; i < 10; i++)
{
a1[i] = i + 1;
}
cout << "a1 is :";
printV(a1);
system("pause");
}
因为函数里面不能定义函数!!!
标签:style 头部 front clu span oid highlight blog use
原文地址:http://www.cnblogs.com/xiaochige/p/6858495.html