title: Visual C++ conditional debugging
body: <p>I am trying to setup a project with conditional debugging. What i want is to have a macro <code>debug</code> which is #defined to some kind of printf/cout/anything when I'm running in debug mode and #defined to null statement when running in production mode. How can I do this:</p>
  
  <p>I have tried using the macro <code>_DEBUG</code> but I always see my arguments printing regardless of which mode I am running in:</p>
  
  <pre><code>struct debugger{template&lt;typename T&gt; debugger&amp; operator ,(const T&amp; v){std::cerr&lt;&lt;v&lt;&lt;" ";return *this;}}dbg;
  #if _DEBUG
      #define debug(...) {dbg,__VA_ARGS__;std::cerr&lt;&lt;std::endl;}
  #else
      #define debug(...) // Just strip off all debug tokens
  #endif
  </code></pre>
  
  <p>In my main: </p>
  
  <pre><code>using namespace std;
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      int a=1,b=2,c=3;
      debug(a,b,c);
      cin&gt;&gt;a;
  }
  </code></pre>
  
  <p>If it helps, I am using Visual studio 2012</p>