I currently have created a List of pointers that point to every 5th element of another List of ints. I am trying to print out this list of pointer to ensure that it is pointing to the right elements of the other list.
I’ve tried various ways to do this but none of them seem to work.
for (int* t = pointersList.begin(); t != pointersList.end(); ++t)
{
cout << *t << endl;
}
or
for (int i = 0; i < pointersList.size(); ++i)
{
int* itr;
itr = pointersList.begin()+i;
cout << *itr;
}
I also tried accesssing it like a vector (cout << pointersList[i];) but none of these seem to work.
I understand that a pointer points to the memory location of an element (and that’s where I use the *) but I never know when I am suppose to use a & or even &*.
Do the Following. This should work. This will get it to print your values of your pointers. Hope this is what you were looking for.