how do you copy the contents of reference to a stl vector to another stl vector by using an assingment operator?
If given vector with contents of random numbers
vector <int> smallVector(smallSize);
and you want to copy the contents inside:
vector <int> copySmallVector(smallSize);
The most intuitive and idiomatic way would be to initialize the second vector as you would any built-in type, using copy initialization. This just works:
vector<int> copySmallVector = smallVector;
There are other alternatives, using other std::vector
constructors. In this case, copy initialization is idiomatic, clear and easy to reason, and no knowledge of other constructors is required.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments