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 8683609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:05:27+00:00 2026-06-12T22:05:27+00:00

I use std::multimap.lower_bound method to return ranged result. But in the same content of

  • 0

I use std::multimap.lower_bound method to return ranged result. But in the same content of container, sometimes I got the wrong iterators pair and it crash my program. I can see the content in container with visual studio, they are all correct. And I use multimap’s find method, it also worked well. It just returns the damned invalid iterators pair and crash my program, and most important of that, I can’t do any test to skip that situation. What’s wrong with this situation?

My example codes as follows:

std::multimap<std::string,std::string>::iterator it = tagged_files.lower_bound("vocal");
std::multimap<std::string,std::string>::iterator it_end = tagged_files.upper_bound("vocal");

For the most part, they worked well. When I print it and it_end with %p(using printf), their results are 8f98ab9(one pointer value) and 0(same key). When I got invalid iterators, debug messages would shows 8f98ab9(same value) and 2b8a839(strange value).

Besides,the size of tagged_files is always the same. No item was inserted at all during whole session even invalid iterators are received. It also proved by printf %d with tagged_files.size().

  • 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-12T22:05:29+00:00Added an answer on June 12, 2026 at 10:05 pm

    When I have an invalid iterator with a std container like map, multimaps, 90% of the time, the reason is I am iterating over the container while I am removing items in this container.

    As soon as an item is removed (or even insterted in some other containers) in a container, the valid state of iterators is no longer guaranteed.

    edit: like the comments below say, rules of invalidation of iterators vary from container to container. cf this question

    edit2: you don’t show us how you dereference your iterators.
    Your iterator is a std::pair, and you should check the returned iterator is not equal to yourContainer.end() before you derefence it. But since you don’t show us the code where you derefence the iterator it is hard to tell. you don’t show us neither the way you output your traces.

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

Sidebar

Related Questions

I'm trying to use std::string instead of char* whenever possible, but I worry I
We are trying to use the std::deque erase member function. The return value of
I am trying to use multimap for the first time but my app will
I am trying use std::copy to copy from two different iterator. But during course
Suppose I want to use std::lower_bound on a std::vector of pointers like this: struct
I changed my class to use std::string (based on the answer I got here
So here is what I would like to do: I use std::pair , but
I am trying to use std::regex in a C++11 piece of code, but it
I'm trying to use std:getline() but getting a strange runtime error: malloc: * error
Why is it wrong to use std::auto_ptr<> with standard containers?

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.