vector<vector<int>>
时间: 2023-10-22 16:09:23 浏览: 84
This is a two-dimensional vector in C++. It is a vector that contains other vectors as its elements. Each element vector can have a different size and can contain any type of data, including integers in this case.
Here's an example of how to declare and initialize a vector<vector<int>>:
```c++
#include <vector>
using namespace std;
int main() {
// Declare and initialize a 2D vector with 3 rows and 4 columns
vector<vector<int>> matrix = { {1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12} };
// Accessing an element in the matrix
int element = matrix[1][2]; // Returns 7
}
```
In this example, `matrix` is a 2D vector with 3 rows and 4 columns. The first row contains the integers 1, 2, 3, and 4, the second row contains 5, 6, 7, and 8, and the third row contains 9, 10, 11, and 12. To access an element in the matrix, we use two square brackets - the first one specifies the row index and the second one specifies the column index. In this case, `matrix[1][2]` returns the element in the second row and third column, which is 7.
阅读全文