Answers for "how to add 2 vectors in 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
0

how to concatenate two vectors in c++

vector<int> a, b;
//fill with data
b.insert(b.end(), a.begin(), a.end());
Posted by: Guest on August-07-2021
-1

how to append two vectors in c++

std::vector<int> AB = A;
AB.insert(AB.end(), B.begin(), B.end());
Posted by: Guest on June-16-2020

Browse Popular Code Answers by Language