1234567891011
struct Address { string street; string city; int suite; friend ostream& operator<<(ostream& os, Address& adr) { return os << adr.street << adr.city << adr.suite; } };
12345678910111213141516171819202122232425262728293031323334
#include <iostream> #include <string> #include <sstream> struct address { std::string street ; std::string city ; int suit = 0 ; friend std::ostream& operator<< ( std::ostream& stm, const address& addr ) { return stm << addr.street << '\n' << addr.city << '\n' << addr.suit << '\n' ; } friend std::istream& operator>> ( std::istream& stm, address& addr ) { std::getline( stm >> std::ws, addr.street ) ; // skip empty lines std::getline( stm, addr.city ) ; return stm >> addr.suit ; } }; int main() { const address a { "Viamonte", "Buenos Aires", 430 }, b { "Universitetskaya Emb", "Saint Petersburg", 199034 } ; std::stringstream stm ; stm << a << "\n\n\n" << b << '\n' ; address c, d ; stm >> c >> d ; std::cout << c << '\n' << d ; }