-4

Most of the people write this in their code.

What dose it mean?

what is the use of #ifndef.

#ifndef ONLINE_JUDGE
   freopen("E://ADpan//in.in", "r", stdin);
   freopen("E://ADpan//out.out", "w", stdout);
#endif
Federico klez Culloca
  • 22,898
  • 15
  • 55
  • 90
Haddi
  • 31
  • 4
  • 10
    Contrary to "Most of the people", this is the first time I've seen this macro. Related: [Why are #ifndef and #define used in C++ header files?](https://stackoverflow.com/questions/1653958/why-are-ifndef-and-define-used-in-c-header-files) – TrebledJ Jun 07 '19 at 07:22
  • 1
    *"Most of the people write this in their code."* Nope, I've never seen this before. *"What dose it mean??"* my guess it it's for conditional compilation for when an online judge compiles it, perhaps because they have different IO settings than your IDE. *"what is the use of #ifndef."* look up "C++ preprocessor" – Blaze Jun 07 '19 at 07:23
  • 5
    A cursory google search led to [this post](https://codeforces.com/blog/entry/14118). To summarize: there are online coding competitions where predefined input is sent to stdin and expected on stdout. When testing and developing locally, some people prefer to hack their program to read from files instead, so they do not have to do something like `test_program < input | diff - expected_output`. Finally, the `ONLINE_JUDGE` macro is defined in the competition environment, so that uses stdin/stdout, while a local compilation will not have that macro and thus read from those files. – Botje Jun 07 '19 at 07:26
  • @Botje, converted your comment into a community wiki answer. – Evg Jun 07 '19 at 08:17

1 Answers1

4

A cursory google search led to this post. To summarize: there are online coding competitions where predefined input is sent to stdin and expected on stdout. When testing and developing locally, some people prefer to hack their program to read from files instead, so they do not have to do something like

test_program < input | diff - expected_output

Finally, the ONLINE_JUDGE macro is defined in the competition environment, so that uses stdin/stdout, while a local compilation will not have that macro and thus read from those files.

Evg
  • 20,870
  • 4
  • 34
  • 69
  • 1
    It could also be used for other things, such as when your program uses non-portable stuff and your compiler/environment is different from the judging servers, measuring execution time, debug code, automatic testing code, etc. – BessieTheCookie Jun 07 '19 at 17:17