how do you copy the contents of reference to a stl vector to another stl vector?

monkey doodle

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);
juanchopanza

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.

edited at
0

Comments

0 comments
Login to comment

Related

C++ STL: How to copy vector iterator?

Efficient assignment of a STL vector to another STL vector (WSL Issue)

Returning a reference from a function that searches an STL vector

Is there an stl way of doing a deep copy of a vector of pointers?

Copy constructor vs assignment operator with STL vector

Copy memory of a class with STL vector type member

c++ renaming the STL vector with another name

Order a vector according to weights stored in another vector using STL algorithms

STL algorithm for Vector Add

Overloading operators for STL Vector

How to properly copy contents of one char array into another when passed to function, WITHOUT using STL?

How to convert a C++ STL vector iterator to a vector reverse iterator?

(c++) STL Vector of STL Vectors

C++: STL sort STL vector of STL array

How do I copy one vector to another vector in Java without updating the original vector?

Assertion Error, using STL Vector

Sort partial vector using STL

vector vs. list in STL

STL vector element removal efficiency

STL vector implementation header size

reserve() Implementation for std::vector in STL

Equals operator on STL vector of pointers

C++ STL : Vector syntax

find() stl in vector in c++

STL vector containing vector causing segfault

Copy contents of a vector into a multiset

Difference between a `vector` created from the std `<vector>` library, and an `STL vector` created from: `<stl_vector.h>`

How to access pair elements nested inside pair in a vector in stl

How to get unique elements from vector using stl?