fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class player {
  5. private:
  6. string first, last, position;
  7. float batave;
  8. int a;
  9.  
  10. public:
  11. friend std::istream & operator>>(std::istream & in, player & p) {
  12. in >> p.first >> p.last >> p.position >> p.batave;
  13. return in;
  14. }
  15.  
  16. friend std::ostream & operator<<(std::ostream & out, const player & p) {
  17. out << p.last << ", " << p.first << ": " << p.position << " (" << p.batave << ")";
  18. return out;
  19. }
  20. };
  21.  
  22. int main() {
  23. player p;
  24. while (cin >> p) {
  25. cout << p << endl;
  26. }
  27. }
Success #stdin #stdout 0s 3472KB
stdin
Chipper Jones 3B 0.303
Rafael Furcal SS 0.281
Hank Aaron RF 0.305
stdout
Jones, Chipper: 3B (0.303)
Furcal, Rafael: SS (0.281)
Aaron, Hank: RF (0.305)