Reputation: 4437
In c++11 you can do this wonderful syntax:
vector<int> numbers = {1, 2, 3};
Is there a way to concatenate a further initializer list onto an existing vector?
numbers.??? ({4, 5, 6});
or
std::??? (numbers, {4, 5, 6});
Upvotes: 27
Views: 10668
Reputation: 19966
You can use std::vector::insert
. Link to example code
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a = {1,2,3};
a.insert(a.end(), {4,5,6});
for(int &i : a) {
cout << i << " ";
}
cout << endl;
return 0;
}
Upvotes: 8
Reputation: 14510
You can use std::vector::insert
for that:
#include <vector>
vector<int> numbers = {1, 2, 3};
numbers.insert( numbers.end(), {4, 5, 6} );
Upvotes: 32
Reputation: 56509
Use std::vector::insert
:
numbers.insert(numbers.end(), {4, 5, 6});
Upvotes: 10