I checked the link Can I overload CArchive << operator to work with std::string? about overloading for string type and I used
CArchive& operator<<( CArchive& ar, string lhs)
{
int size_t = lhs.size();
ar << size_t;
ar.Write( lhs.c_str(), size_t );
return ar;
}
CArchive& operator>>( CArchive& ar, string lhs)
{
int size_t = lhs.size();
ar >> size_t;
lhs.resize(size);
ar.Read(&lhs[0], size);
}
And I declared the overloaded operators in my header function as a friend.
class CArrow : public CObject
{
DECLARE_SERIAL(CArrow)
friend CArchive& operator<<( CArchive& ar, std::string lhs);
friend CArchive& operator>>( CArchive& ar, std::string lhs);
...
...
}
But the >>
operator gives me blank output. When I don't use as an operator, just read and write in my serialization function, they work for only one string variable. However, I have more than one string to store and load. Is there any other way to serialize the string type? or What is the problem with this overloaded functions?