Hacker-M's blog

By Hacker-M, 3 years ago, In English

Hi !

I was googling how to debug faster without writing many cerrs and I found out this blog, then I found out that I don't want to write this much code in my default code on my computer then when I wan in tourist's live stream I saw he is using a local include and I want to use something like that, can anybody pls help, Btw I am using sublime text.

This is the code I want to make include for it

I just want to write this part in my code when I am practicing :

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
  • Vote: I like it
  • -12
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Create a debug.h file and put your debugging template there and include it's path inside your template.

debug.h
If you include path like this, you don't need to comment out debug statements while submitting
  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    thanks, But how can I find the path? I did the same thing you said but I pasted the debug.h file in includes of Mingw do I have to copy that path?

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      You can keep the debug.h file anywhere on your system. Copy the path to your file and include it in your template.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        well it doesn't still work bro :/ I copied the file in my desktop and I am using windows can you help to figure it out pls :/

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it +1 Vote: I do not like it

          Keep your cpp file and debug.h file in the same folder and use #include "debug.h"

          • »
            »
            »
            »
            »
            »
            3 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            I did everything you said but it's not working for me too :|

            • »
              »
              »
              »
              »
              »
              »
              3 years ago, # ^ |
                Vote: I like it +3 Vote: I do not like it

              To actually include this debug.h file you will have to compile your code with the ON_PC flag as follows: g++ -DON_PC <your-normal-compile-flags> a.cpp. To do this just edit your build system and add -DON_PC tag among the other tags.

              Also, in the screenshot attached you have not defined what pb is.

              • »
                »
                »
                »
                »
                »
                »
                »
                12 months ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                can you please explain how i can do it for visual studio 22 ?

            • »
              »
              »
              »
              »
              »
              »
              3 years ago, # ^ |
                Vote: I like it +3 Vote: I do not like it

              Either use -DON_PC flag while compiling or replace #ifdef ON_PC with #ifndef ONLINE_JUDGE

              Read about compilation flags, #ifdef, #ifndefs to know that they do.

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
          Rev. 2   Vote: I like it +3 Vote: I do not like it

          You have to pass -DON_PC if you are using GNU compiler.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      #include "Headers/debug.cpp"

      Make a folder Header where you generally have your .cpp files and keep your debug.cpp file there.

»
23 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can you explain me what's the meaning of this #define debug(x...) and why have you use dots in front of x (x...) ?