ghost1733's blog

By ghost1733, history, 4 years ago, In English

I was looking submission of other user and i noticed something common in them,

#ifdef ONLINE_JUDGE

#define OJ \

freopen(file".in", "r", stdin); \

freopen(file".out", "w", stdout);

#else

#define OJ ;

#endif

I want to know how this works .Please help. And how to use it and what does it do?

  • Vote: I like it
  • +8
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +7 Vote: I do not like it

Auto comment: topic has been updated by ghost1733 (previous revision, new revision, compare).

»
4 years ago, # |
  Vote: I like it +7 Vote: I do not like it

Auto comment: topic has been updated by ghost1733 (previous revision, new revision, compare).

»
4 years ago, # |
  Vote: I like it +7 Vote: I do not like it

Auto comment: topic has been updated by ghost1733 (previous revision, new revision, compare).

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I think it works when we use local compilers and add input and output files. but when we use some online judge all these lines are just ignored.

»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

When one uses an online IDE, the input is taken as text and output is printed (in a box) as text. This effect is not available in local IDEs by default. To add this functionality, we include these lines, that specify two text files we have saved in our local device called input.txt and output.txt. By doing so, on writing input in input.txt and then building/running the code, the output will be written to output.txt.