Hacker-M's blog

By Hacker-M, 13 months ago,

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

| Write comment?
 » 13 months ago, # |   +13 Create a debug.h file and put your debugging template there and include it's path inside your template. debug.h#include using namespace std; void __print(int x) {cout << x;} void __print(long x) {cout << x;} void __print(long long x) {cout << x;} void __print(unsigned x) {cout << x;} void __print(unsigned long x) {cout << x;} void __print(unsigned long long x) {cout << x;} void __print(float x) {cout << x;} void __print(double x) {cout << x;} void __print(long double x) {cout << x;} void __print(char x) {cout << '\'' << x << '\'';} void __print(const char *x) {cout << '\"' << x << '\"';} void __print(const string &x) {cout << '\"' << x << '\"';} void __print(bool x) {cout << (x ? "true" : "false");} template void __print(const pair &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';} template void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";} void _print() {cout << "]"< void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #define deb(x...) cout << #x << " = ["; _print(x) templateT amax(T &a,T1 b){if(b>a)a=b;return a;} templateT amin(T &a,T1 b){if(b // replace with your path #else #define deb(x...) #endif 
•  » » 13 months ago, # ^ | ← 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?
•  » » » 13 months ago, # ^ |   +3 You can keep the debug.h file anywhere on your system. Copy the path to your file and include it in your template.
•  » » » » 13 months ago, # ^ |   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 :/
•  » » » » » 13 months ago, # ^ |   +1 Keep your cpp file and debug.h file in the same folder and use #include "debug.h"
•  » » » » » » 13 months ago, # ^ |   0 I did everything you said but it's not working for me too :|
•  » » » » » » » 13 months ago, # ^ |   +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 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.
•  » » » » » » » 13 months ago, # ^ |   +3 Either use -DON_PC flag while compiling or replace #ifdef ON_PC with #ifndef ONLINE_JUDGERead about compilation flags, #ifdef, #ifndefs to know that they do.
•  » » » » » » » » 10 months ago, # ^ |   0 i did this but the error comes like this: Can't compile file: program.cpp: In function 'void solve()': program.cpp:28:14: error: 'imie' was not declared in this scope debug() << imie(bal) imie(ans) imie(i) imie(s[i]); ^~~~ program.cpp:28:14: note: suggested alternative: 'time' debug() << imie(bal) imie(ans) imie(i) imie(s[i]);please help
•  » » » » » » » » » 10 months ago, # ^ |   0 Bruh :| you don't have to write debug() << ... -_- you have to write debug(the thing you need)
•  » » » » » 13 months ago, # ^ | ← Rev. 2 →   +3 You have to pass -DON_PC if you are using GNU compiler.
•  » » » 13 months ago, # ^ |   0 #include "Headers/debug.cpp"Make a folder Header where you generally have your .cpp files and keep your debug.cpp file there. The colored debugging header file that I usehttps://github.com/prabhavdogra/CPSnippets/blob/main/Miscellaneous/debug.cpp
 » 2 months ago, # |   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...) ?
•  » » 2 months ago, # ^ |   +1 ... means variable number of arguments
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 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.