I'm trying to cloning the vector itself, for example if the vector is [2,3] it will become [2,3,2,3].
This is my program:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> a;
a.push_back(2);
a.push_back(3);
for(int i: a)
{
a.push_back(i);
}
for(int i: a)
cout << i << " ";
return 0;
}
So I'm just pushing the elements to the vector itself but the output is [2,3,2,0]
. I don't understand why.
Help me with this problem.