Sunday, September 1, 2019

Printing value of pointer in a vector of pointer c++

here is my code:



vector *ptr;
int *tab = new int(20);

ptr->push_back(tab);
cout << *(ptr->at(0)) << endl;


I want to print 20 on the screen, but I got a segmentation fault.
when I use only



vector ptr;



it prints out fine. I get easily the result just by doing :



*ptr.at(0);


But I want to use a pointer not a simple variable.
Can I have some enlightenment?



Thanks

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...