sstream using input and output file
<p>So i have a file data3.txt which basically looks like this:</p>

<pre><code>#file:data.txt
#data inputs
1 1234 +0.2 23.89 6.21
2 132 -0.03 3.22 0.1
3    32 0.00 31.50   4.76
</code></pre>

<p>And I want to take the first 3 columns to write into a new file using stringtreams</p>

<pre><code>#include &lt;cctype&gt;
#include &lt;sstream&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
#include &lt;string&gt;
using namespace std;
int main(){
  string line;
  float curr_price, change;
  int stock_number;
  ifstream fin("data3.txt");
  istringstream iss;
  ostringstream oss;
  if(!fin){
    cerr&lt;&lt;"Can't open a file";
  }
  ofstream outfile("data2.txt");
  while (getline(fin,line)){
    iss.clear();
    iss.str(line);
    iss&gt;&gt;stock_number&gt;&gt;curr_price&gt;&gt;change;
    while(isspace(iss.peek()))
      iss.ignore();
    while(iss.str() == "#")
      iss.ignore();
    if( iss.str()==""){
      break;
    }
    oss&lt;&lt;stock_number&lt;&lt;"\t"&lt;&lt;curr_price&lt;&lt;"\t"&lt;&lt;change&lt;&lt;"\n";
    outfile&lt;&lt;oss.str();
  }
}
</code></pre>

<p>but i my output file looks nasty:</p>

<pre><code>0   0   0
0   0   0
0   0   0
0   0   0
0   0   0
1   1234    0.2
0   0   0
0   0   0
1   1234    0.2
2   132 -0.03
0   0   0
0   0   0
1   1234    0.2
2   132 -0.03
3   32  0
</code></pre>

<p>I have no idea from where does zeros came from, and if i put the ofstream out of the while loop then it will only print the last data row</p>
