C ++中具有用户定义大小的2D向量
向量的向量称为2D向量。
算法
Begin
Declare a variable v to the 2D vector type.
Initialize values to the vector v.
Print “the 2D vector is:”.
for (int i = 0; i < v.size(); i++)
for (int j = 0; j < v[i].size(); j++)
print the value of 2D vector v[i][j].
End.示例
#include <iostream>
#include <vector> //header file for 2D vector in C++
using namespace std;
int main() {
vector<vector<int> > v{ { 4,5, 3, 10 }, // initializing 2D vector with values.
{ 2, 7, 11 },
{ 3, 2, 1, 12 } };
cout<<"the 2D vector is:"<<endl;
for (int i = 0; i < v.size(); i++) { // printing the 2D vector.
for (int j = 0; j < v[i].size(); j++)
cout << v[i][j] << " ";
cout << endl;
}
return 0;
}输出结果
the 2D vector is: 4 5 3 10 2 7 11 3 2 1 12
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬