title: How to define an upper limit for an std::ostringstream after which all appended data is discarded?
body: <p>I have some existing code that uses a <code>std::ostringstream</code> as an temporary buffer. To increase robustness, I want to define an upper limit for the buffer size (e.g., 16 KB). When the limit is exceeded, all following data that is append, should be silently discarded. Ideally, after logging a warning.</p>
  
  <p>What is the simplest way of doing it? <code>std::ofstream</code> seems to have no efficient way of getting its current size. I can only think of <code>my_stream.str().size()</code>, which seems to be highly inefficient.</p>
  
  <p>Of course, I can manually keep track of the number of inserted chars by keeping an extra counter, but maybe there is an elegant alternative that I am missing. I saw that <code>ofstringstream</code> has an internal buffer (<code>rdbuf()</code>) that can be replaced.</p>
  
  <p>Is it possible (and practical) to use it to solve my problem?</p>