Блог пользователя Hacker-M

Автор Hacker-M, 2 года назад, По-английски

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
  • Проголосовать: нравится
  • -12
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

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
  • »
    »
    2 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    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?

    • »
      »
      »
      2 года назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

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

      • »
        »
        »
        »
        2 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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 :/

        • »
          »
          »
          »
          »
          2 года назад, # ^ |
            Проголосовать: нравится +1 Проголосовать: не нравится

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

          • »
            »
            »
            »
            »
            »
            2 года назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

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

            • »
              »
              »
              »
              »
              »
              »
              2 года назад, # ^ |
                Проголосовать: нравится +3 Проголосовать: не нравится

              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.

            • »
              »
              »
              »
              »
              »
              »
              2 года назад, # ^ |
                Проголосовать: нравится +3 Проголосовать: не нравится

              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.

        • »
          »
          »
          »
          »
          2 года назад, # ^ |
          Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

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

    • »
      »
      »
      2 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      #include "Headers/debug.cpp"

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

»
14 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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