Answers for "concatenate two vectors c++"

C++
0

concatenate two vectors c++

#include <vector> // vector 
#include <iostream> // output 
using namespace std;

int main()
{
  // two vectors to concatenate
  vector<int> A = {1,3,5,7};
  vector<int> B = {2,4,6,8};
  // vector that will hold the combined values of A and B
  std::vector<int> AB = A;
  AB.insert(AB.end(), B.begin(), B.end());
  // output 
  for (auto i : AB) {
      cout << i << ' ';
  }
}
Posted by: Guest on August-29-2021

Browse Popular Code Answers by Language