title: Clean code to printf size_t in C++ (or: Nearest equivalent of C99's %z in C++)
body: <p>I have some C++ code that prints a <code>size_t</code>:</p>
  
  <pre><code>size_t a;
  printf("%lu", a);
  </code></pre>
  
  <p>I'd like this to compile without warnings on both 32- and 64-bit architectures.</p>
  
  <p>If this were C99, I could use <code>printf("%z", a);</code>.  But AFAICT <code>%z</code> doesn't exist in any standard C++ dialect.  So instead, I have to do</p>
  
  <pre><code>printf("%lu", (unsigned long) a);
  </code></pre>
  
  <p>which is really ugly.</p>
  
  <p>If there's no facility for printing <code>size_t</code>s built into the language, I wonder if it's possible to write a printf wrapper or somesuch such that will insert the appropriate casts on <code>size_t</code>s so as to eliminate spurious compiler warnings while still maintaining the good ones.</p>
  
  <p>Any ideas?</p>
  
  <p><hr>
  <i>Edit</i> To clarify why I'm using printf: I have a relatively large code base that I'm cleaning up.  It uses printf wrappers to do things like "write a warning, log it to a file, and possibly exit the code with an error".  I might be able to muster up enough C++-foo to do this with a cout wrapper, but I'd rather not change every warn() call in the program just to get rid of some compiler warnings.</p>