vector声明
初始化
获取数据
修改元素值
追加元素
遍历
定义二维的vector
二维vector遍历
#include <iostream>
#include <vector>using namespace std;int main(){// vector 声明vector<string> name_vector;// vector 初始化vector<int> score = {10,20,30,40,50,60};// vector 获取数据cout << "获取第一个位置的数据" <<score[0]<< endl;cout << "获取第一个位置的数据="<< score.at(0)<< endl;//修改元素值score[0] = 19;// 追加元素score.push_back(70);cout << score[6]<< endl;//遍历for (int i = 0; i < sizeof(score)/sizeof(int); ++i) {cout << "第"<< i << "个元素的值="<< score[i]<< endl;}for(int v:score){cout << "v=" <<v <<endl;}// 二维vectorvector<vector<int>> scores = {{10,20,30,40,50,60},{11,21,31,41,51,61},{12,22,32,42,52,62}};// 二维vector遍历for(vector<int> vi:scores){for(int v:vi){cout << v << '\t';}cout << endl;}return 0;
}