fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. enum FACE { NORTH, SOUTH, EAST, WEST };
  6.  
  7. struct Direction {
  8. FACE face;
  9. };
  10.  
  11. std::ostream& operator<<(std::ostream& os, Direction const& dir)
  12. {
  13. std::string face = "";
  14. switch(dir.face)
  15. {
  16. case(NORTH):
  17. os << "NORTH";
  18. break;
  19. case(SOUTH):
  20. os << "SOUTH";
  21. break;
  22. case(EAST):
  23. os << "EAST";
  24. break;
  25. case(WEST):
  26. os << "WEST";
  27. break;
  28. }
  29. return os << face;
  30. }
  31.  
  32. int main(){
  33. Direction dir;
  34. dir.face = EAST;
  35. cout << dir; // I want this to print EAST instead of having to do dir.face
  36. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
EAST