Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

TaskForce141's blog

By TaskForce141, history, 6 weeks ago, In English

I use a header named printContainer.h for printing STL containers for debugging purposes, but I always have to comment it out before submission , sometimes I forget and get Compilation error which causes much problem and most importantly every second counts here... my template is like this:

#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include<iomanip>
#include<cstring>
#include <queue>
#include "Templates/printContainer.h"

//Rest of the code

please tell me what to do? I heard ifdef or endif works but I couldn't make it work...maybe I am using the wrong way.

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

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it
#ifndef ONLINE_JUDGE
#include "Templates/printContainer.h"
#endif
»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Yeah you need to use ifdef and endif and define some custom macro when compiling:

#ifdef LOCAL
#include "Templates/printContainer.h" 
#endif

And now whenever you're compiling you use

g++ -DLOCAL A.cpp

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    can I completely copy this code and submit in cf? and not get CE?

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes. This just means that you only include this header if you compile with the macro LOCAL, which is not present in the online judge.

      Also I just checked some of the other answers and they might be more convenient because you just compile normally without the need to provide a custom macro (5yearold's answer) so ig you can just use that.

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

see any of my submissions, u need to use #ifndef ONLINE_JUDGE and #endif directives. the code under these directives will not be executed by online judges of platforms like codeforces, atcoder and codechef. hope this helps.

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

#ifndef ONLINE_JUDGE #include "Templates/printContainer.h" #else // define functions defined in template as empty as shown in comments below // #define debug(...) ; // #define crndl ; #endif