5

I am trying to append one vector to another vector, both vectors being same in "dimension".

int main()
{
std::vector<int> v1={1,2,3,4,5},v2={10,11,12};
//v1.push_back(v2)?
//v1 and v2 have same dimensions

}

Without creating loops and pushing back individual element, is there any way to achieve similar to this python statements?

v1=[1,2,3,4,5]
v2=[10,11,12]
v1.extend(v2)
print(v1)

gives [1, 2, 3, 4, 5, 10, 11, 12]

er344tre
  • 85
  • 1
  • 1
  • 5

1 Answers1

12

v1.insert(v1.end(), v2.begin(), v2.end());

Dhruv Sehgal
  • 1,402
  • 1
  • 13
  • 15