fork download
  1. #define cose_says( ... )
  2.  
  3. //------------------------------------------------------------------------------------------
  4. #include <ctime>
  5.  
  6. class WATCH
  7. {
  8. clock_t begin;
  9.  
  10. public:
  11. auto operator!() { begin = clock(); }
  12. auto operator~()
  13. {
  14. return (float)( clock() - begin ) / CLOCKS_PER_SEC;
  15. }
  16. };
  17.  
  18. WATCH watch;
  19.  
  20. //------------------------------------------------------------------------------------------
  21. #include<io.h>
  22.  
  23. class redirect
  24. {
  25. FILE* fp;
  26. int fd;
  27. fpos_t pos;
  28.  
  29. public:
  30. redirect( const char* filename, const char* mode = "wb", FILE* as = stdout )
  31. {
  32. fgetpos( as, &pos );
  33. fd = _dup( fileno( as ) );
  34. fp = freopen( filename, mode, as );
  35. }
  36. ~redirect()
  37. {
  38. fflush( fp );
  39. _dup2( fd, fileno( fp ) );
  40. close( fd );
  41. clearerr( fp );
  42. fsetpos( fp, &pos );
  43. }
  44. };
  45.  
  46. cose_says
  47. (
  48. 생성자에서 표준출력이나 표준입력을 file로 redirect 해주고,
  49. 소멸자에서 원복시키는 구조
  50. )
  51. //------------------------------------------------------------------------------------------
  52.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:21:15: fatal error: io.h: No such file or directory
 #include<io.h>
               ^
compilation terminated.
stdout
Standard output is empty