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 -
std::map<std::string,User>::iterator it = usermap.begin();
usermap.insert (it, std::pair<string,User>(object.userid,object));
The code I am using to write the objects in a .bin file is -
map<std::string, User>::iterator it;
for ( it = usermap.begin(); it != usermap.end(); it++ )
{
myfile2 << "Object:" << it->second << "\n";
}
But the error I am getting when I am trying to run the code is -
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& std::operator<<(std::basic_ostream&, const unsigned char*) operator<<(basic_ostream& __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<_Tp>::operator->, User> >()->std::pair, User>::second’ (type ‘User’) to type ‘const unsigned char*’ myfile2 << "Obejct: " << it->second << "\n";
Any solutions for resolving the error?
My User class is defined as -
class User
{
public:
string userid; string uid; string gid; string gecos; string directory; string shell;
User() {}
};
User
class have an overloadedoperator <<
that you are trying to call? – user7860670