I followed a tutorial online on how to use an iterator with a vector and it worked perfectly, but I wanted to try something myself, which is iterate through a pointer of type vector, I cant seem to figure it out.
// for(vector<string>::iterator it = pVect.begin(); it != pVect.end(); it++)
for(vector<string>::iterator it = pVect->begin(); it != pVect->end(); it++)
I figured it out, the compiler suggested using the member selection arrow and that worked. However, I am wondering why I use the member selection arrow and not the dot operator? I BELIEVE that the Arrow operator can only be used with pointers and the dot operator, well idk. (it's been a while since i learned about those.)
> I BELIEVE that the Arrow operator can only be used with pointers
pVect is a pointer
1 2 3 4 5 6 7 8 9 10 11
// pVect is a pointer to an object of type vector; begin and end are members of vector
for(vector<string>::iterator it = pVect->begin(); it != pVect->end(); it++)
{
cout << *it << endl;
}
// (*pVect) is an object of type vector; begin and end are members of vector
for(vector<string>::iterator it = (*pVect).begin(); it != (*pVect).end(); it++)
{
cout << *it << endl;
}