Saturday, April 6, 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

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...