combine 2 vectors c++ code example
Example 1: c++ vector combine two vectors
vector1.insert(vector1.end(), vector2.begin(), vector2.end());
Example 2: joining two vectors in c++
// my linkedin : https://www.linkedin.com/in/vaalarivan-prasanna-3a07bb203/
vector<int> AB;
AB.reserve(A.size() + B.size()); // preallocate memory
AB.insert(AB.end(), A.begin(), A.end());
AB.insert(AB.end(), B.begin(), B.end());
//eg : A = {4, 1}, B = {2, 5}
//after the 2 insert operations, AB = {4, 1, 2, 5}
Example 3: how to append two vectors in c++
std::vector<int> AB = A;
AB.insert(AB.end(), B.begin(), B.end());