fork download
  1. #include <iostream>
  2. //#include <iomanip>
  3. using namespace std;
  4.  
  5. class Bruch
  6. {
  7. public:
  8. int Zaehler;
  9. int Nenner;
  10. };
  11.  
  12. istream& operator >>(istream& stream, const char *literal)
  13. {
  14. while (*literal)
  15. if (stream.get() != *literal++)
  16. {
  17. stream.clear(ios::failbit);
  18. break;
  19. }
  20.  
  21. return stream;
  22. }
  23.  
  24. istream& operator >>(istream& stream, Bruch& bruch)
  25. {
  26. stream >> bruch.Zaehler >> "/" >> bruch.Nenner;
  27. return stream;
  28. }
  29.  
  30. ostream& operator <<(ostream& stream, Bruch bruch)
  31. {
  32. stream << bruch.Zaehler << "/" << bruch.Nenner;
  33. return stream;
  34. }
  35.  
  36. int main() {
  37. Bruch b;
  38.  
  39. cin >> b;
  40. if (cin)
  41. cout << "parsed correctly: " << b;
  42. else
  43. cout << "parse error!";
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 16064KB
stdin
5/2
stdout
parsed correctly: 5/2