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
Create a debug.h file and put your debugging template there and include it's path inside your template.
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?
You can keep the debug.h file anywhere on your system. Copy the path to your file and include it in your template.
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 :/
Keep your cpp file and debug.h file in the same folder and use #include "debug.h"
I did everything you said but it's not working for me too :|
To actually include this
debug.h
file you will have to compile your code with theON_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.can you please explain how i can do it for visual studio 22 ?
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.
You have to pass -DON_PC if you are using GNU compiler.
#include "Headers/debug.cpp"
Make a folder
Header
where you generally have your .cpp files and keep yourdebug.cpp
file there.https://github.com/prabhavdogra/CPSnippets/blob/main/Miscellaneous/debug.cpp
Can you explain me what's the meaning of this #define debug(x...) and why have you use dots in front of x (x...) ?
... means variable number of arguments
define — preprocessor directive, the essence of which is that you can set a certain combination of characters, when compiled, the combination will be replaced by a given string. Read more on the Microsoft website — https://learn.microsoft.com/en-us/cpp/preprocessor/hash-define-directive-c-cpp?view=msvc-160&viewFallbackFrom=vs-2019.