Advertisement
MeehoweCK

Untitled

Dec 4th, 2020
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Osoba
  6. {
  7.     friend istream& operator>>(istream&, Osoba&);
  8.     friend ostream& operator<<(ostream&, const Osoba&);
  9.     string imie;
  10.     string nazwisko;
  11. public:
  12.     Osoba() : imie(""), nazwisko("") {}
  13.     Osoba(string, string);
  14. };
  15.  
  16. Osoba::Osoba(string name1, string name2) : imie(name1), nazwisko(name2) {}
  17.  
  18. istream& operator>>(istream& is, Osoba& obj)
  19. {
  20.     string imie;
  21.     string nazwisko;
  22.     is >> imie >> nazwisko;
  23.     obj = Osoba(imie, nazwisko);
  24.     return is;
  25. }
  26.  
  27. ostream& operator<<(ostream& os, const Osoba& obj)
  28. {
  29.     os << obj.imie << ' ' << obj.nazwisko;
  30.     return os;
  31. }
  32.  
  33. int main()
  34. {
  35.     Osoba nowa_osoba;
  36.     cin >> nowa_osoba;
  37.     cout << nowa_osoba;
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement