Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7822409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:55:03+00:00 2026-06-02T07:55:03+00:00

// Erase the missing items vector<AlignedFDRData>::size_type StandardNum = FDRFreq.at(0).fData.size(); vector<AlignedFDRData>::iterator iter = FDRFreq.begin(); while

  • 0
// Erase the missing items
vector<AlignedFDRData>::size_type StandardNum = FDRFreq.at(0).fData.size();
vector<AlignedFDRData>::iterator iter = FDRFreq.begin(); 
while (iter != FDRFreq.end()){
    if( iter->fData.size() < StandardNum){
        FDRFreq.erase(iter);
    }
    else{
        ++iter;
    }
}

This part is used to erase the FDRFreq vector item, in which the data length is smaller than the standard number, but the debug assertion failed: vector iterators incompatible. I am a green hand in C++ STL, thanks for your kindly help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:55:04+00:00Added an answer on June 2, 2026 at 7:55 am

    Your code needs to become

    while (iter != FDRFreq.end()){
        if( iter->fData.size() < StandardNum){
            iter = FDRFreq.erase(iter);
        }
        else{
            ++iter;
        }
    }
    

    “vector iterators incompatible” means that the iterator you’re using has been invalidated – that is to say, there is no guarantee that the elements it points to still exist at that memory location. An erase of a vector element invalidates the iterators following that location. .erase returns a new, valid iterator you can use instead.

    If you’re new to STL, I highly recommend you read Scott Myer’s Effective STL (and Effective C++, while you’re at it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do erase call in std::set invalidate iterator ? As i have done below 5th
Is it allowed to erase an element pointed by iterator, and advance the same
I need to take a C++ vector with potentially a lot of elements, erase
I was surprised to find out the vector::erase move elements on calling erase .
I was trying to erase a range of elements from map based on particular
They seems to erase the line and enter the insertion mode.
How can I ensure that all data that I've erase from the db tables,
I wrote a disk utility that allowed you to erase whole physical drives. it
I have looked at various methods ranging from string.erase/ ispunct etc. and I cant
I have a problem using the string function erase with iterators. The function below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.