frendall frendall - 3 years ago 97
C++ Question

Match a variable with an iterater using a vector object array

I have an iterator

ic
and a variable
ncount
. I am trying to match
ncount
with the iterator. I would appreciate any help or advice.
Thanks in advance.

for(ic = ackAttacky.begin();ic !=ackAttacky.end())
{
if(alien[ncount].alienBulletDead == true){
ic = ackAttacky.erase(ic);
alien[ncount].alienBulletDead = false;
alien[ncount].alienFired = false;
alienBulletCounter -=1;
cout << ncount << " " << ackAttacky.size() << endl;
}
else
++ic;
}

Answer Source

How about std::distance?

nCount = std::distance(ackAttacky.begin(), ic);

http://www.cplusplus.com/reference/iterator/distance/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download