-3

I found in this code on codeforces . I am not that expert please guide me the use of these lines of code The question just reads an input string of integers of maximum length 1000

ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE  
freopen("test.in", "r", stdin); 
#endif
Biffen
  • 6,249
  • 6
  • 28
  • 36
Vinayak Sangar
  • 107
  • 2
  • 12
  • Which part, exactly, do you not understand? – Biffen Dec 15 '16 at 06:46
  • Sir, I did not understand the first four lines I have shown in highlighting the four lines.It would be great if you would help :) – Vinayak Sangar Dec 15 '16 at 10:42
  • That's not specific enough. Where should we start? With the origins of the lowercase letter i? C++ syntax? Or the subtleties of IO buffering? Tell us what you understand and which parts, specifically, you don't. – Biffen Dec 15 '16 at 11:17

1 Answers1

0

The first line is basically done to speedup reading files since these features are not generally required in competitive coding (take this with a grain of salt):

  1. Usage of ios_base::sync_with_stdio can be found in Using scanf() in C++ programs is faster than using cin?
  2. Usage of cin.tie(0), cout.tie(0) can be found in Why do we need to tie std::cin and std::cout?

As for using ONLINE_JUDGE it has been explained in codeforces blog. Basically, when codeforces runs the code online it adds the ONLINE_JUDGE flag. In your case if you are running the code at home you can ignore ONLINE_JUDGE flag and it will read your test file test.in. The same code while running in Codeforces will have ONLINE_JUDGE set and will ignore the freopen("test.in", "r", stdin); line and run its own test cases.

Community
  • 1
  • 1
rmist
  • 463
  • 1
  • 6
  • 15