vector<int>& nums)什么意思
时间: 2023-10-22 20:20:56 浏览: 146
华为OD真题&模拟题资源
A vector is a dynamic array in C++ that allows us to store and manipulate a collection of elements of the same data type. The vector<int> is a specific type of vector that stores integers (int). Here is an example of how we can declare and initialize a vector<int>:
```
#include <vector>
#include <iostream>
using namespace std;
int main() {
// declare and initialize a vector of integers
vector<int> myVector = {1, 2, 3, 4, 5};
// print the vector elements
for (int i = 0; i < myVector.size(); i++) {
cout << myVector[i] << " ";
}
cout << endl;
return 0;
}
```
Output:
```
1 2 3 4 5
```
In this example, we declare a vector of integers called `myVector` and initialize it with five integer values. We then use a for loop to iterate through the elements of the vector and print them to the console. The output shows the values 1, 2, 3, 4, and 5, separated by spaces.
阅读全文