#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> a{ 1, 2, 3 };
copy(a.begin(), a.end(), back_inserter(a));
for (const int& x : a)
cout << x << ' ';
}
Output:
1 2 3 1 -572662307 -572662307
Expected output:
1 2 3 1 2 3
I have no idea why is this happening. What's is the reason for this behavior?