title: Iterating map in C++ containing class objects
body: <p>I am creating a map in C++ which contains a integer key and the value is an object of class User. I am able to insert the object into the map with the following code - </p>
  
  <pre><code>std::map&lt;std::string,User&gt;::iterator it = usermap.begin();
          usermap.insert (it, std::pair&lt;string,User&gt;(object.userid,object));
  </code></pre>
  
  <p>The code I am using to write the objects in a .bin file is -</p>
  
  <pre><code>map&lt;std::string, User&gt;::iterator it;
  for ( it = usermap.begin(); it != usermap.end(); it++ )
  {
  myfile2 &lt;&lt; "Object:" &lt;&lt; it-&gt;second &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>But the error I am getting when I am trying to run the code is - </p>
  
  <p><strong>In file included from /usr/include/c++/4.8.2/iostream:39:0,
                   from a3part2_5.cpp:2:
  /usr/include/c++/4.8.2/ostream:548:5: note: template std::basic_ostream&amp; std::operator&lt;&lt;(std::basic_ostream&amp;, const unsigned char*)
       operator&lt;&lt;(basic_ostream&amp; __out, const unsigned char* __s)
       ^
  /usr/include/c++/4.8.2/ostream:548:5: note:   template argument deduction/substitution failed:
  a3part2_5.cpp:90:31: note:   cannot convert ‘it.std::_Rb_tree_iterator&lt;_Tp>::operator->, User> >()->std::pair, User>::second’ (type ‘User’) to type ‘const unsigned char*’
    myfile2 &lt;&lt; "Obejct: " &lt;&lt; it->second &lt;&lt; "\n";</strong></p>
  
  <p>Any solutions for resolving the error?</p>
  
  <p>My User class is defined as - </p>
  
  <pre><code>class User 
  { 
  public: 
  string userid; string uid; string gid; string gecos; string directory; string shell; 
  User() {} 
  };
  </code></pre>