The usage of two-dimensional array of vector in C++

Usage:
In C++, add #include to the header file, and add the statement in the function:
vector vi[100];
or
vector< vector> vi(100);

// vi[0]~vi[99] each is a vector container

As an example:

Code:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    
    
    vector<int> vi[100];//必须定义行数,列可以不定义
    //vector< vector<int> > vi(100);可以替换上面语句
    for(int i = 0; i < 10; i++)
    {
    
    
        for(int j = 0; j < 10; j++) // 列数为10
        {
    
    
            a[i].push_back(5);
        }
    }
    for(int i = 0; i < 10; i++)
    {
    
    
        for(int j = 0; j < 10; j++)
        {
    
    
            cout  << a[i][j] << " " ;
        }
        cout << endl;
    }
    return 0;
}

Output result:

Insert picture description here
This is a simple example. For the specific use of vector two-dimensional array, please refer to other blog PAT B1005.

Guess you like

Origin blog.csdn.net/qq_27538633/article/details/105983156