fork download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4.  
  5. class Logger {
  6. std::stringstream ss;
  7. public:
  8. ~Logger() {
  9. std::cout<< ss.str();
  10. }
  11.  
  12. // General for all types supported by stringstream
  13. template<typename T>
  14. Logger& operator<<(const T& arg) {
  15. ss << arg;
  16. return *this;
  17. }
  18.  
  19. // You can override for specific types
  20. Logger& operator<<(bool b) {
  21. ss << (b? "Yep" : "Nope");
  22. return *this;
  23. }
  24. };
  25.  
  26.  
  27. int main() {
  28. Logger() << "Is the answer " << 42 << "? " << true;
  29. return 0;
  30. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Is the answer 42? Yep