#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#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.