I just write a code to copy a vector value of another vector and when I edit the second vector the original one should be impact so here the code there is something that I don't understand :
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<int>a={1,2,3,4,5};
vector<int>*b=new vector<int>(6);
b=&a;
(*b).push_back(7);
for(int i=0;i<=6;i++){
cout<<a[i];
}
cout<<endl;
for(int i=0;i<=6;i++){
cout<<(*b).at(i);
}
delete b; } the question is why I get this result when I run the program: 1234570 123457 why I dont get the last zero in both of them and thanx~
Please login or Register to submit your answer