I'm a newbie in C++ STL. I have some problem in the below code with respect to the output.Why is this not providing the expected output?
#include<iostream>
#include<algorithm>
#include<vector>
#include<iterator>
using namespace std;
void show(vector<int> vect)
{
for(int i=0;i<vect.size();i++)
{
cout<<vect[i]<<" ";
}
}
int main()
{
int arr[5]={ 1, 2, 3, 4, 5 };
vector<int> vect1(arr,arr+5);
vector<int>::iterator it;
it=vect1.begin();
advance(it,3);
copy(vect1.begin(),vect1.end(),inserter(vect1,it));
show(vect1);
return 0;
}
Expected output:1 2 3 1 2 3 4 5 4 5
Actual output:1 2 3 1 0 3 4 5 4 5
Can anyone help me in finding out where it went wrong?