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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:42:35+00:00 2026-05-27T01:42:35+00:00

My question is almost identical to this one , but the solution there hasn’t

  • 0

My question is almost identical to this one, but the solution there hasn’t resolved my error.

In main.h I have:

#include <map>
#include <string>

std::map<std::string, int64_t> receive_times;

And in main.cpp:

std::map<std::string, int64_t>::const_iterator iter;
std::map<std::string, int64_t>::const_iterator eiter = receive_times.end();

for (iter = receive_times.begin(); iter < eiter; ++iter)
  printf("%s: %ld\n", iter->first.c_str(), iter->second);

However, when I try and compile I get the following error:

error: invalid operands to binary expression ('std::map<std::string, int64_t>::const_iterator' (aka '_Rb_tree_const_iterator<value_type>') and 'std::map<std::string, int64_t>::const_iterator'
  (aka '_Rb_tree_const_iterator<value_type>'))
  for (iter = receive_times.begin(); iter < eiter; ++iter)
                                     ~~~~ ^ ~~~~~

The solution in the question I linked to at the top is because there was a missing #include <string>, but obviously I have that included. Any hints?

  • 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-05-27T01:42:36+00:00Added an answer on May 27, 2026 at 1:42 am

    Iterators are not relationally comparable, only for equality. So say iter != eiter.

    A less noisy way to write the loop:

    for (std::map<std::string, int64_t>::const_iterator iter = receive_times.begin(),
         end = receive_times.end(); iter != end; ++iter)
    {
      // ...
    }
    

    (Usually best to typedef the map type!)

    Or, in C++11:

    for (auto it = receive_times.cbegin(), end = receive_timed.cend(); it != end; ++it)
    

    Or even:

    for (const auto & p : receive_times)
    {
      // do something with p.first and p.second
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry - my question is almost identical to this one but since it didn't
I'm almost certain I know the answer to this question, but I'm hoping there's
Firstly there is an almost identical question but the answer is not really satisfactory.
This is almost similar question to this one: - Dealing with timezones in PHP
I am almost embarrassed to ask this question, but as a long time C
This is almost certainly a very silly question, but for some reason I'm having
This question is almost identical to How to efficiently count the number of keys/properties
This is almost identical to this question asked by another user, and is the
I have almost the same problem as this unanswered question . The only difference
ok, yesterday I posted almost identical question here , but I wasn't able to

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.