Avatar ·

How to append one vector to the end of another vector in C++?

Hello everyone. I just started learning C++ and STL, and I have a problem with vectors. I'm writing a small program that processes data from different sources. I have two `std::vector` objects, and I need to merge them into one: all elements of the second vector should be appended to the end of the first. I tried several approaches, but none work as I expected. Here's a simplified example of my code: ```cpp #include #include int main() { std::vector vec1 = {1, 2, 3}; std::vector vec2 = {4, 5, 6}; // Trying to append vec2 to vec1 vec1.push_back(vec2); // Compilation error! // Or like this: // vec1.insert(vec1.end(), vec2); // Also not quite right for (int x : vec1) { std::cout << x << " "; }