Help printing the contents of this map

I am trying to figure out what this map contains but I can't seem to print its contents. Here is the initialization:

  std::map<uint64_t, uint8_t>  devices_seen;

here is how I am attempting to print the contents:

  for(std::map<uint64_t, uint8_t>::const_iterator it = devices_seen.begin();
        it != devices_seen.end(); ++it)
        std::cout << it->first << " " << it->second.first << " " << it->second.second << "\n";

and the error I am getting is:

  error: request for member 'first' in 'it.std::_Rb_tree_const_iterator<_Tp>::operator-> [with _Tp =
 std::pair<const long long unsigned int, unsigned char>]()->std::pair<const long long unsigned int,
 unsigned char>::second', which is of non-class type 'const unsigned char'

will I need to do some kind of conversion/cast in order to print the contents of this map?
Last edited on
Hello vysero,

You define the map as having a "key" of "unit64_t", (a unsigned long long), and a value of "unit8_t", (an unsigned char). Yet when you try to print in the for loop you art trying to access the "value" as if it is a std::pair. Which is it?

When I removed ".first" and ".second" the errors went away.

Also it is better to post the whole code as the error may not start in the for loop as you think.

Hope that helps,


Edit: My mistake. I do not use "unit64_t" and "unit8_t" that often and did not realize that they are unsigned.
Last edited on
Registered users can post here. Sign in or register to post.