Personal I made a simple code but I have a problem. I did an "increase" function to increase the size of a vector; The function receives the vector and passes the values of that vector to an auxiliary vector. So I can delete the vector, allocate the new size, and retrieve the values from it, because they were saved in the aux vector. The problem is he's printing trash. If I print the vector inside the function it leaves everything right but in the main it goes wrong. Can anyone help? Follow the code:
#include<iostream>
using namespace std;
void aumentar(int *vetor, int tam){
int *aux, i;
aux= new int[tam];
for(i=0; i<tam; i++){
aux[i]=vetor[i];
}
cout<<"aux:"<<endl;
for(i=0; i<tam; i++){
cout<<aux[i]<<" ";
}
cout<<endl;
delete []vetor;
vetor = new int[11];
for(i=0; i<tam; i++){
vetor[i]=aux[i];
}
vetor[tam]=10;
for(i=0; i<11; i++){
cout<<vetor[i]<<" ";
}
cout<<endl;
}
int main(){
int *vetor, i;
vetor = new int[10];
for(i=0; i<10; i++){
vetor[i]=i;
}
for(i=0; i<10; i++){
cout<<vetor[i]<<" ";
}
cout<<endl;
aumentar(vetor,10);
cout<<"Resultado"<<endl;
for(i=0; i<11; i++){
cout<<vetor[i]<<" ";
}
cout<<endl;
}