vector向量使用方法汇总
Posted thebreakofdawn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vector向量使用方法汇总相关的知识,希望对你有一定的参考价值。
vector之二维向量
一维向量:以指定类型数据为元素
二维向量:以向量为元素
vector<int> 盛放int类型的数
vector<vector<int>> 变量名; 盛放vector<int>类型的向量
一维向量for循环和二维向量for循环一样!
实例运行:

1 #include<iostream> 2 #include<vector> //下面用到vector所以需要包含头文件 3 4 using namespace std; 5 6 //在主函数中,返回值类型为int类型 7 int main() 8 { 9 vector<vector<int>> array_td; //二维向量的格式对吗? 10 11 vector<int> array_od(3, 2); //初始化格式对吗? 12 13 for (int i = 0; i <= 4; i++) 14 { 15 array_td.push_back(array_od); //push_back用法:括号中是要压缩的元素(整数或向量) 16 } 17 //出错点:数组中最大索引值总是小于数组维度-1 18 for (int i = 0; i < array_td.size(); i++) //array_td.size()中括号! 19 { 20 for (int j=0; j<array_td[0].size(); j++) 21 { 22 cout << array_td[i][j]; //二维数组的元素的引用 23 } 24 cout << endl; 25 } 26 return 0; //最后返回值为0 27 }
https://www.cnblogs.com/fuhang/p/9077624.html
https://blog.csdn.net/laobai1015/article/details/51218871
https://www.cnblogs.com/otakuhan/p/8598790.html
以上是关于vector向量使用方法汇总的主要内容,如果未能解决你的问题,请参考以下文章