title: Is it possible to iterate through a text file lines and use stringstream to parse each line?
body: <p>What I am trying to do is read from a text file each line while parsing using sstream library. I got the program to run but it's stuck in a loop. </p>
  
  <blockquote>
    <p>Program:</p>
  </blockquote>
  
  <pre><code>string date;
  int time;
  float amount;
  
  ifstream testFile("test.txt");
  string token;
  string line;
  
  while(!testFile.eof()) {
  
      while(getline(testFile,token,',')){
          line += token + ' ';
      }
      stringstream ss(line); 
      ss &gt;&gt; date;
      ss &gt;&gt; time;
      ss &gt;&gt; amount;
  
      cout &lt;&lt; "Date: " &lt;&lt; date &lt;&lt; " ";
      cout &lt;&lt; "Time: " &lt;&lt; time &lt;&lt; " ";
      cout &lt;&lt; "Amount: " &lt;&lt; amount &lt;&lt; " ";
      cout&lt;&lt;endl;
  
      ss.clear();
  
  }    
  testFile.close();
  </code></pre>
  
  <blockquote>
    <p>test.txt:</p>
  </blockquote>
  
  <pre><code>10/12/1993,0800,7.97
  11/12/1993,0800,8.97
  </code></pre>
  
  <blockquote>
    <p>Wanted output:</p>
  </blockquote>
  
  <pre><code>Date: 10/12/1993 Time: 0800 Amount: 7.97
  Date: 11/12/1993 Time: 0800 Amount: 8.97
  </code></pre>
  
  <p>How can I effectively produce this?</p>