title: Automated replace of sprintf function with c++ string functions
body: <p>We have a large amount of "demo" code that uses sprintf and cstrings to construct filenames. I'd like to replace it with c++ strings  to allow very long filenames and because it gives a cleaner syntax.</p>
  
  <p>So essentially we need to convert blocks like</p>
  
  <pre><code>ofstream some_file;
  char filename[100];
  sprintf(filename,"%s/soln%i.dat",a.c_str(), b);
  some_file.open(filename);
  </code></pre>
  
  <p>into something like</p>
  
  <pre><code>ofstream some_file((a + "soln" + to_string(b) + ".dat").c_str());
  </code></pre>
  
  <p>However because this is used in a lot of places I'd like to use some kind of automatic conversion (i.e. sed expressions, emacs function/macros, visual studio?, etc.). The difficulties (that I can see) are:</p>
  
  <ol>
  <li><p>The contents of the sprintf statement can be anything. (So we need to parse an sprintf statement?)</p></li>
  <li><p>some_file and filename could be declared anywhere, could be named anything and often are reused for output to multiple files. (So we need to parse C++?)</p></li>
  </ol>
  
  <p>Is this possible/feasible?</p>
  
  <p>For bonus points can we avoid having to call .c_str() on the string (without changing the ofstream constructor)?</p>