Hello everyone!
I would like your help regarding this:
I have a tuple vector which i must iterate through, and accessing the vector data to decide wether to erase or not the current vector element.
My code :
typedef tuple <int, CString, int, int> pc_data;
vector <pc_data> pc_vec;
//Assume that pc_vec is filled with elements somewhere here...
//This code is not working.
//Exception : vector subject out of range because of the size dynamically changing i suppose
for (int i=0; i<num_of_pcs; i++)
{
if(std::get<2>(pc_vec[i])==0)
pc_vec.erase(pc_vec.begin()+i);
}
//second try
//No exception here but the dynamic size of the vector again won't let me access all elements sequentially
for (size_t i = 0; i < pc_vec.size(); i++)
{
if(std::get<2>(pc_vec[i])==0)
pc_vec.erase(pc_vec.begin()+i);
}
//third try
//use iterator
vector<pc_data>::iterator it = pc_vec.begin();
//I don't know how to access the current element data in this situation..(?)
for ( ; it != pc_vec.end(); )
{
if(std::get<2>(/*WHAT SHOULD I USE TO ACCESS THE CURRENT ELEMENT HERE??*/)==0)
{
it = pc_vec.erase(it);
}
else
{
++it;
}
}
Could you please suggest me a way to do it?
Thanks in advance and hope my question is clear enough.