fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct Point { int x, y; };
  6. struct Line { Point a, b; };
  7. struct Color { float r, g, b; string name; };
  8. struct ColorfulLine { Line line; Color color; };
  9.  
  10. istream& operator>>(istream& in, Point& point) { return in >> point.x >> point.y; };
  11. istream& operator>>(istream& in, Line& line) { return in >> line.a >> line.b; };
  12. istream& operator>>(istream& in, Color& color) { return in >> color.name >> color.r >> color.g >> color.b; };
  13. istream& operator>>(istream& in, ColorfulLine& line) { return in >> line.color >> line.line; };
  14.  
  15. int main() {
  16. Line line;
  17. while(cin >> line) { cout << "We've got a line!\n"; }
  18.  
  19. cin.clear();
  20.  
  21. ColorfulLine color_line;
  22. while(cin >> color_line) { cout << "We've got a colorful line!\n"; }
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 3472KB
stdin
1 2    3  4
5 6    7  8 
9 10   11 12

red    1 0 0    1 2    3 4
green  0 1 0    5 6    7 8
blue   0 0 1    9 10   11 12
stdout
We've got a line!
We've got a line!
We've got a line!
We've got a colorful line!
We've got a colorful line!
We've got a colorful line!