The usage and function of vector<int> nums = vector<int> (number)

#include<vector>
using namespace std;
int main()
{
    // vector<int> nums;
    // nums = vector<int> (3);
    vector<int> nums = vector<int> (3);
    int l = nums.size();
    cout<<l<<endl;//输出为3
}

Here are two rare ways to define the length of the nums vector. vector<int>(3) defines a value without a name. Remember to add parentheses here to assign it to nums.

When Likou was working on the question, I saw someone else write it like this. It was the first time I saw this way of writing, and no one mentioned this usage when I searched, so I was almost caught in it.

Guess you like

Origin blog.csdn.net/qq_18116643/article/details/125668562