12345678910111213141516171819
friend std::ostream& operator << (std::ostream& lhs, const image& rhs) { DebugText("writing a image to a file"); int stringsize=rhs.strfilename.size(); lhs<<stringsize; lhs.write(reinterpret_cast< const char*>(&rhs.strfilename),rhs.strfilename.size()); return lhs; } friend std::istream& operator >> (std::istream& lhs, image& rhs) { DebugText("reading image from a file"); string chrfilename; int stringsize; lhs>>stringsize; lhs.read(reinterpret_cast<char*>(&chrfilename), stringsize); rhs.readimagefile(chrfilename);//FileName it's a property return lhs; }
12345678
std::ostream& operator<< ( std::ostream& stm, const image& img ) { return stm << img.strfilename << '\n' ; } std::istream& operator>> ( std::istream& stm, image& img ) { // http://www.cplusplus.com/reference/string/string/getline/ if( std::getline( stm, img.strfilename ) ) img.readimagefile( img.strfilename ) ; return stm ; }