title: how to reuse stringstream
body: <p>These threads do NOT answer me:</p>
  <p><a href="https://stackoverflow.com/questions/7623650/">resetting a stringstream</a></p>
  <p><a href="https://stackoverflow.com/questions/20731/">How do you clear a stringstream variable?</a></p>
  <pre class="lang-cpp prettyprint-override"><code>std::ifstream file( szFIleName_p );
  if( !file ) return false;
  
  // create a string stream for parsing
  
  std::stringstream szBuffer;
  
  std::string szLine;     // current line
  std::string szKeyWord;  // first word on the line identifying what data it contains
  
  while( !file.eof()){
  
      // read line by line
  
      std::getline(file, szLine);
  
      // ignore empty lines
  
      if(szLine == &quot;&quot;) continue;
  
      szBuffer.str(&quot;&quot;);
      szBuffer.str(szLine);
      szBuffer&gt;&gt;szKeyWord;
  </code></pre>
  <p><code>szKeyword</code> will always contain the first word, <code>szBuffer</code> is not being reset. I can't find a clear example anywhere on how to use stringstream.</p>
  <p>New code after answer:</p>
  <pre class="lang-cpp prettyprint-override"><code>...
  szBuffer.str(szLine);
  szBuffer.clear();
  szBuffer&gt;&gt;szKeyWord;
  ...
  </code></pre>
  <p>Ok, thats my final version:</p>
  <pre class="lang-cpp prettyprint-override"><code>std::string szLine;     // current line
  std::string szKeyWord;  // first word on the line identifying what data it contains
  
  // read line by line
  
  while( std::getline(file, szLine) ){
  
      // ignore empty lines
  
      if(szLine == &quot;&quot;) continue;
  
      // create a string stream for parsing
  
      std::istringstream szBuffer(szLine);
      szBuffer&gt;&gt;szKeyWord;
  </code></pre>