📄 vector.cpp
字号:
// vector.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <vector>
int main(int argc, char* argv[])
{
using namespace std;
int i=10,j;
vector<int> v(i);
// 赋值
for(j=0;j<10;j++)
{
v[j]=j;
}
for(j=0;j<10;j++)
cout<< v[j]<<" ";
cout<<endl;
// cout<<"v 的长度: "<<v.size()<<endl;
// cout<<v.front()<<endl;
// cout<<v.back()<<endl;
// v.push_back(11);
// v.push_back(12);
// cout<<v.back()<<" "<<"v 的长度: "<<v.size()<<endl;
// v.resize(20);
// cout<<"v 的长度: "<<v.size()<<endl;
// v.pop_back();
// v.pop_back();
// cout<<"v 的长度: "<<v.size()<<endl;
// cout<<"v 的容量: "<<v.capacity()<<endl;
// v.reserve(100);
// cout<<v.back()<<" "<<"v 的长度: "<<v.size()<<endl;
// cout<<"v 的容量: "<<v.capacity()<<endl;
// cout<<v.at(9)<<endl;
// cout<<v[50]<<endl;
cout<<v.at(50)<<endl;
#if 0
try
{
cout<<v.at(50)<<endl;
}
catch(out_of_range)
{
cout<<"数组访问越界"<<endl;
}
#endif
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -