DON_BD's blog

By DON_BD, history, 5 years ago, In English
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
Rev. 11   Vote: I like it 0 Vote: I do not like it
  1. #ifdef _DEBUG and #endif are C++ preprocessor directives that conditionally compile the code inside this block when the _DEBUG flag is defined either in the compiler call as gcc .... -D_DEBUG or inside the program source as #define _DEBUG. C++ Preprocessor

  2. freopen("input.txt", "r", stdin); and freopen("output.txt", "w", stdout) are C library function calls that reuse stdin and stdoutstandard input and standard output stream file pointers as file pointers to the files input.txt and output.txt, respectively. Subsequent standard C stream input/output function calls such as scanf(), printf(), getchar(), putchar(), puts() etc. that read/write data from/to stdin/stdout are redirected to read/write data from/to the files input.txt/output.txt. This saves the typing and/or copy-and-paste time of the program input data during the debugging phase, and stores the program output data in file instead or printing it to the computer screen. FILE * freopen ( const char * filename, const char * mode, FILE * stream )