Click here to Skip to main content
16,006,570 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionErasing a vector<vector inside a for-loop Pin
jc0dex29-Mar-06 19:03
jc0dex29-Mar-06 19:03 
AnswerRe: Erasing a vector Pin
Rob Caldecott29-Mar-06 19:52
Rob Caldecott29-Mar-06 19:52 
AnswerRe: Erasing a vector<vector inside a for-loop Pin
Johann Gerell29-Mar-06 19:53
Johann Gerell29-Mar-06 19:53 
GeneralRe: Erasing a vector<vector inside a for-loop Pin
jc0dex30-Mar-06 3:53
jc0dex30-Mar-06 3:53 
GeneralRe: Erasing a vector<vector inside a for-loop Pin
Johann Gerell30-Mar-06 5:18
Johann Gerell30-Mar-06 5:18 
GeneralRe: Erasing a vector<vector inside a for-loop Pin
jc0dex30-Mar-06 6:09
jc0dex30-Mar-06 6:09 
GeneralRe: Erasing a vector<vector inside a for-loop Pin
jc0dex30-Mar-06 6:12
jc0dex30-Mar-06 6:12 
GeneralRe: Erasing a vector<vector inside a for-loop Pin
Johann Gerell30-Mar-06 8:40
Johann Gerell30-Mar-06 8:40 
Assuming this is what you have:
typedef std::vector< _PACKETS > PacketList;
std::vector< PacketList > _PacketLists;
then this is probably what you want:
for(std::vector< PacketList >::iterator listIt = _PacketLists.begin(); listIt != _PacketLists.end(); ++listIt)
{
    PacketList& packetList = *listIt;

    for(PacketList::iterator packetIt = packetList.begin(); packetIt != packetList.end(); ++packetIt)
    {
        _PACKETS& packets = *packetIt;

        if(packets.seqNumber == seqNum)
        {
            packetList.erase(packetIt);

            return;
        }
    }
}
which simply means that you iterate over all elements of the outer vector, and for each inner vector, all elements is iterated until the one matching the seqNum criteria is found. It's then erased from that inner vector and the iteration is stopped.

If you want to continue searching the remaining inner vectors (which I'd guess), then break instead of return.

--
The Blog: Bits and Pieces
QuestionIs it a lvalue? Pin
Twinsen72429-Mar-06 18:27
Twinsen72429-Mar-06 18:27 
AnswerRe: Is it a lvalue? Pin
Rage29-Mar-06 23:52
professionalRage29-Mar-06 23:52 
GeneralRe: Is it a lvalue? Pin
Twinsen72430-Mar-06 15:46
Twinsen72430-Mar-06 15:46 
AnswerRe: Is it a lvalue? Pin
jc0dex30-Mar-06 4:10
jc0dex30-Mar-06 4:10 
GeneralRe: Is it a lvalue? Pin
Twinsen72430-Mar-06 15:32
Twinsen72430-Mar-06 15:32 
GeneralRe: Is it a lvalue? Pin
jc0dex30-Mar-06 15:44
jc0dex30-Mar-06 15:44 
GeneralRe: Is it a lvalue? Pin
Twinsen72430-Mar-06 15:49
Twinsen72430-Mar-06 15:49 
GeneralRe: Is it a lvalue? Pin
jc0dex30-Mar-06 17:41
jc0dex30-Mar-06 17:41 
GeneralRe: Is it a lvalue? Pin
Twinsen7242-Apr-06 15:54
Twinsen7242-Apr-06 15:54 
QuestionRTTI question Pin
alex.barylski29-Mar-06 17:36
alex.barylski29-Mar-06 17:36 
QuestionUniscribe woes.... Pin
Super Lloyd29-Mar-06 16:17
Super Lloyd29-Mar-06 16:17 
Questionabout hide windows Pin
FlyWithYou29-Mar-06 14:53
FlyWithYou29-Mar-06 14:53 
AnswerRe: about hide windows Pin
Stephen Hewitt29-Mar-06 15:35
Stephen Hewitt29-Mar-06 15:35 
QuestionA question Pin
yaaqub29-Mar-06 14:48
yaaqub29-Mar-06 14:48 
AnswerRe: A question Pin
Rage29-Mar-06 23:54
professionalRage29-Mar-06 23:54 
QuestionA mistake when submit aticle Pin
includeh1029-Mar-06 9:22
includeh1029-Mar-06 9:22 
AnswerRe: A mistake when submit aticle Pin
David Crow29-Mar-06 9:29
David Crow29-Mar-06 9:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.