GOOGLED IT YET COULDNT FIND ANTHING
inline void debugMode() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
i was solving a problem on codeforces, though i couldn’t do so… so i tried looking at someone else’s code and found this. As being a newbie couldn’t get why are we looking for if ONLINE_JUGES CONSTANT is set, if not opening a file in read mode… are we taking all inputs in one go to fasten process?? can anyone be a bit descriptive to this as i have already looked at codechef and stackoverflow and codeforces links explaining this…
This is a general practice by c++ programmers who code in a text editor rather than an IDE. By default the ONLINE_JUDGE constant is defined when submitting any code in most online judges like Codechef and Codeforces. Thus it provides a way for the code to determine whether the code is being run in an online judge or a local machine, where the constant is not defined. Generally this flag is used in order for the code to read and write to and from file rather than stdin when run on a local machine and read and write from stdin and stdout when run in an online judge. This it eliminates the need to again again edit the code, for reading from a file, and again for reading from stdin.
Refer to this video for more details : https://m.youtube.com/watch?v=DlPTG4AkuqU