Detailed explanation of freopen function and its use in OJ evaluation system
To open a binary file, add a "b" character.
redirect open
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
redirect recovery
- win
freopen("CON", "r", stdin); freopen("CON", "w", stdout);
- linux
freopen("/dev/console", "r", stdin) freopen("/dev/console", "w", stdout);
In the OJ system, common usage:
when compiling locally
#define DONLINE_JUDGE
/**
*
*/
#ifdef DONLINE_JUDGE
freopen("stdin.txt","r",stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
Or add it at compile time -DONLINE_JUDGE
or use Cmake to add it to CMakeLists.txtadd_compile_definitions(DONLINE_JUDGE)