0

I am programming a little engine and I want to implement a debug mode. I tried to write to the console when I am linking the file with #include but it doesn't work. Here what I am trying to do :

main.cpp

#ifdef _DEBUG
    #include "debug.h"
    #include "vld.h"
#endif

int main(int argc, char** argv){
    // some code
    return 0;
}

Debug.h

#ifndef __DEBUG_H
#define __DEBUG_H

    #include <iostream>

    #ifdef _DEBUG
        std::cout << "DEBUG MODE" << std::endl;
    #endif

#endif

I kept only the code that was essential. I do understand that I need to execute the std::cout inside the main but I can't because I want the DEBUG MODE to be printed first in the console. The #include vld.h is an external header file that does what I am trying to do ( I don't have access to that file ).

  • 1
    Simple answer is: You don't. But many compilers have special preprocessor directives to output informative, warning or error messages though. Look through the documentation for your compiler and its preprocessor (hint, you might look for something like `#info`) – Some programmer dude Sep 09 '15 at 01:12
  • 1
    Also, don't use symbol names (compiler or preprocessor) with double leading underscore, [those are reserved in all scopes](http://stackoverflow.com/a/228797/440558). – Some programmer dude Sep 09 '15 at 01:13
  • 1
    Thanks for your answer. I found this directive `#pragma message("DEBUG MODE")`. It is fine for me because I just wanted to know when I am in debug mode. I also modified all my classes so they are not using double leading underscore. – Michael Masson Sep 09 '15 at 01:39

0 Answers0