fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Foo {
  5. int x, y;
  6.  
  7. friend ostream& operator<<(ostream& out, const Foo& f) {
  8. return out << "x: " << f.x << "\ty: " << f.y;
  9. }
  10.  
  11. friend istream& operator>>(istream& in, Foo& f) {
  12. return in >> f.x >> f.y;
  13. }
  14.  
  15. public:
  16. Foo(int x=0, int y=0): x(x), y(y) {}
  17. };
  18.  
  19. int main() {
  20. Foo f;
  21. cin >> f;
  22. cout << f << endl;
  23.  
  24. int x, y;
  25. cin >> x >> y;
  26. Foo f2(x, y);
  27. cout << f2 << endl;
  28. return 0;
  29. }
Success #stdin #stdout 0s 3344KB
stdin
10 20
20 10
stdout
x: 10	y: 20
x: 20	y: 10