mexStream.h 623 B

1234567891011121314151617181920212223
  1. #include <iostream>
  2. namespace igl
  3. {
  4. // http://stackoverflow.com/a/249008/148668
  5. // Class to implement "cout" for mex files to print to the matlab terminal
  6. // window.
  7. //
  8. // Insert at the beginning of mexFunction():
  9. // mexStream mout;
  10. // std::streambuf *outbuf = std::cout.rdbuf(&mout);
  11. // ...
  12. // ALWAYS restore original buffer to avoid memory leak problems in matlab
  13. // std::cout.rdbuf(outbuf);
  14. //
  15. class mexStream : public std::streambuf
  16. {
  17. public:
  18. protected:
  19. virtual std::streamsize xsputn(const char *s, std::streamsize n);
  20. virtual int overflow(int c = EOF);
  21. };
  22. }