vector<int>& res
时间: 2023-10-22 21:17:19 浏览: 107
A vector is a container class in C++ that represents a dynamic array. It is defined in the standard library header <vector> and is part of the STL (Standard Template Library).
A vector<int> is a vector that stores integer values. It can be used to store a sequence of integers that can be accessed using an index. Here is an example of how to create and use a vector<int>:
```
#include <vector>
#include <iostream>
int main() {
std::vector<int> numbers = {1, 2, 3, 4, 5};
// Accessing elements
std::cout << numbers[0] << std::endl; // Output: 1
// Iterating over elements
for (auto num : numbers) {
std::cout << num << " ";
}
// Output: 1 2 3 4 5
// Adding elements
numbers.push_back(6);
// Removing elements
numbers.pop_back();
return 0;
}
```
In this example, we create a vector of integers called numbers and initialize it with some values. We then access elements using the [] operator and iterate over them using a for loop. We also demonstrate how to add and remove elements from the vector using the push_back() and pop_back() methods.
阅读全文