OJ:STL之vector

#include<iostream>
#include<vector>
using namespace std;
vector<int> v(100);//()声明一维数组 且赋v[i]初值0
vector<int> v2[100];//[]声明二维数组 且赋v2[i][0]初值0
int main(){
	cout << "v" << endl;
	cout << v.size() << endl;//一维size为数组长度
	v.push_back(33);
	cout << v.size() << endl;
	cout << v[0] << endl;
	cout << v[3] << endl;
	cout << "v2" << endl;
	cout << v2[44].size() << endl;//二维size为某行列长度 初始为0
	v2[44].push_back(55);
	cout << v2[44].size() << endl;
	cout << v2[44][0] << endl;
	//二维某位在被push_back之前无空间,直用报错
	//如v2[44][3]=66;或cout << v2[44][3]会报错
	return 0;
}

猜你喜欢

转载自blog.csdn.net/guomengkai/article/details/86758709