1: #include <iostream>
2: #include <vector>
3:
4: using namespace std;
5:
6: vector <int >a(1);//vector<struct>name(size)
7: int main()
8: {
9: a[0]=1;//input
10: a[1]=2;
11: cout<<a[0]<<endl;//output the first data
12: cout<<a.size()<<endl;//output the size of the vector
13: //a.resize(1);//resize the vector
14: cout<<a.size()<<endl;
15: cout<<a[1]<<endl;
16: return 0;
17: }
输出为
1
1
1
2
则说明即使超界访问,vector也可以拥有容错性。