Advertisement
jasonpogi1669

Push Back All Elements from a Vector to another Vector using C++

Sep 1st, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     vector<int> a = {1, 2, 3, 4, 5};
  7.     vector<int> b = {6, 7, 8, 9, 10};
  8.     a.insert(a.end(), b.begin(), b.end());
  9.     // elements in vector 'a'
  10.     for (auto& x : a) {
  11.         cout << x << " ";
  12.     }
  13.     cout << '\n';
  14.     b.clear();
  15.     // elements in vector 'b'
  16.     for (auto& x : b) {
  17.         cout << x << " ";
  18.     }
  19.     cout << '\n';
  20.     return 0;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement