Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class TextOut
  4. {
  5.     friend TextOut& operator<<(TextOut& to, std::string text);
  6.  
  7. private:
  8.     std::ostream& stream() { return std::cout; }
  9. };
  10.  
  11. TextOut& operator<<(TextOut& to, std::string text)
  12. {
  13.     to.stream() << text;
  14.     return to;
  15. }
  16.  
  17. template<typename T>
  18. TextOut& operator<<(TextOut& to, T val)
  19. {
  20.     to << std::to_string(val);
  21.     return to;
  22. }
  23.  
  24. int main()
  25. {
  26.     TextOut to;
  27.     to << 5;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement