title: automatically replace characters in stringstream
body: <p>I was searching for a way to replace characters in a <code>ostringstream</code> after I've filled it with string content but there are only some very inefficient solutions which extract the <code>string</code>, modify it and put it back into the <code>ostringstream</code>.</p>
  
  <p>Now I wonder if there's a way to automatically replace those characters at the time I add the string. E.g.</p>
  
  <pre><code>ostringstream my_json;
  my_json &lt;&lt; replace_singlequotes;  # modify the stringsteam once
  my_json &lt;&lt; "{'this':";
  my_json &lt;&lt; " 'is valid JSON'}";
  std::cout &lt;&lt; my_json.str();
  
  output:
  {"this": "is valid JSON"}
  </code></pre>
  
  <p>Can you write a custom filter for a <code>ostringstream</code> similar to the format modifiers like <code>std::hex</code>, etc. which modifies a given string before piping it into the stream?</p>
  
  <p>Or is there any other way to replace characters in a <code>ostringstream</code> except running <code>std::replace()</code> on <code>my_json.str()</code> as suggested in other questions and howtos? </p>