My goal is to fill a vector v
with 1,1,1,2,2,2
(the length of the sequence is variable) by appending together two temporary vectors. I know that this is possible, however I was wondering if there is a one-liner solution.
Here is the code I tried that did not work.
int length = 3;
vector<int> v(length, 1);//fill three 1s.
v.insert(v.end(), vector(length, 2));//to fill three 2s, failed.
for (size_t i = 0; i < v.size(); i++)
{
cout << v[i] << ", "; // I want 1 1 1 2 2 2
}