Search code examples
c++preprocessorconditional-compilation

How to define a preprocessor macro name


#ifdef _DEBUG
 
                 cout<<"key_str"<<key_str<<endl;
                 cout<<"val_str"<<val_str<<endl;
 #endif

I am reading others' code with a _DEBUG macro. I want to print these cout's content to screen. Is there an option to turn it on either in compiling or running the program? I am new to c++.


Solution

  • You can pass definitions with the -D flag to g++:

    $ g++ -D_DEBUG -g -O0 main.cpp -o main