Wednesday 11 September 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...