title: Optionally print to stdout at runtime
body: <p>I have output in a C++ program that I only want to see if a "verbose" option is specified at runtime. I've found lots of methods to use preprocessor <code>#define</code> statements to control debugging output when compiling, but I can't find any ways to do this at runtime short of wrapping every <code>cout</code> in <code>if(verbose)</code>.</p>
  
  <p>In pseudocode, I'd like to transform:</p>
  
  <pre><code>if(verbose)
    cout &lt;&lt; "Some text: " &lt;&lt; variable &lt;&lt; endl;
  ...
  if(verbose)
    cout &lt;&lt; "Other text: " &lt;&lt; var &lt;&lt; endl;
  </code></pre>
  
  <p>Into:</p>
  
  <pre><code>if(verbose)
    //block cout
  
  cout &lt;&lt; "Some text: " &lt;&lt; variable &lt;&lt; endl;
  cout &lt;&lt; "Other text: " &lt;&lt; var &lt;&lt; endl;
  </code></pre>
  
  <p>Is there some way to optionally redefine cout at runtime so those lines silently print nothing? Better yet would be a more flexible approach that allows some output while blocking others.</p>