Accessing the associated string of a stringstream object
<p>I am trying to access the associated string of a stringstream object and keep iterators to it, but am not able to know whether this would be safe. Here is the code :</p>

<pre><code>  stringstream HTMLss;   // string stream of HTML document

  // ... (load up HTMLss with HTML) 

  const string &amp; HTMLstr = HTMLss.str();   // grab reference to associated string 
  string::const_iterator begin,end;
  begin = HTMLstr.begin();                 // grab iterators to that string as well
  end = HTMLstr.end();
  boost::match_results&lt;std::string::const_iterator&gt; matches;

  // do some processing, updating the iterators along the way
  while( boost::regex_search(begin, end, matches, metaexp) )
    {
      string key( matches[1].first, matches[1].second );
      string raw_val( matches[2].first, matches[2].second );

      // ... some processing which does NOT manipulate HTMLss stringstream in any way

      begin = matches[2].second;   // updating the iterator
    }
</code></pre>

<p>My question is -- is the above safe to do ? Can it be assumed that one can keep/update iterators that point to the associated string of the stringstream object, and that the behavior is going to be correct? There are no other calls to any string stream function. How can one know whether this is safe or not? </p>
