In many C++ and C codes i saw
#ifndef ONLINE_JUDGE
Can someone please explain me this concept and why and when is it used?
Please … . .
Thanks in Advance
In many C++ and C codes i saw
#ifndef ONLINE_JUDGE
Can someone please explain me this concept and why and when is it used?
Please … . .
Thanks in Advance
Brother, you can get it from here : Help | CodeChef & Save time with -ONLINE_JUDGE - Codeforces
It is convenient to use the conditional directive ONLINE_JUDGE for debugging solutions.
#include <stdio.h>
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
return 0;
}
Note that the function freopen may also be used with stream input/output.
#include <iostream>
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
int a, b;
std::cin >> a >> b;
std::cout << a + b << std::endl;
return 0;
}