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?
Iterators are not relationally comparable, only for equality. So say
iter != eiter.A less noisy way to write the loop:
(Usually best to
typedefthe map type!)Or, in C++11:
Or even: