Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. /* ---------------------------------------------------------------------------
  2. * ** This software is in the public domain, furnished "as is", without technical
  3. * ** support, and with no warranty, express or implied, as to its usefulness for
  4. * ** any purpose.
  5. * **
  6. * ** The file provide a way to avoid printing interleaved words in a multithreaded
  7. * ** environment. It works like qDebug() for the Qt framework
  8. * **
  9. * ** Usage :
  10. * ** Print() << " The debug value = " << 42;
  11. * ** Print() << " The debug value = " << 56;
  12. * **
  13. * ** Author: Arthur Sonzogni
  14. * ** -------------------------------------------------------------------------*/
  15.  
  16. #ifndef PRINT_HEADER_GUARD_823
  17. #define PRINT_HEADER_GUARD_823
  18.  
  19. #include <iostream>
  20. #include <sstream>
  21.  
  22. class Print
  23. {
  24. public:
  25. template<typename T> Print& operator<<(const T& x)
  26. {
  27. ss << x;
  28. return *this;
  29. }
  30. ~Print()
  31. {
  32. std::cerr << ss.rdbuf() << std::endl;
  33. }
  34. private:
  35. std::stringstream ss;
  36. };
  37.  
  38. #endif /* end of include guard: PRINT_HEADER_GUARD_823 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement