title: Read data from file C++
body: <p>I would like to extract the max values for each node but my program prints me just the max for node number 1 eight times:</p>
  
  <p><strong>223
  223
  223
  223
  223
  223
  223
  223</strong></p>
  
  <p>Given the input data I expect to see:</p>
  
  <p><strong>223
  736
  898
  543
  367
  726
  568
  563</strong></p>
  
  <p><a href="http://i.stack.imgur.com/kqO2H.png" rel="nofollow">this is my textfile </a></p>
  
  <p>Any help 
  Thanks in advance </p>
  
  <p>this is my code: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;numeric&gt;
  using namespace std;
     template &lt;typename T&gt;
     string IntToString(T Number)
      {   stringstream ss;
        ss &lt;&lt;Number;
       return ss.str();
       }
  int main() {
                  ifstream ifs;
          ofstream ofs;
                  double maxTxEnergy = 0;
                  vector&lt;double&gt; TxE;
                  double maxRxEnergy = 0;
                  double FullTxEnergy = 0;
                  double FullRxEnergy = 0;
  for (int i = 1; i &lt;=1; i++){    
          stringstream ss;
          ss &lt;&lt;i&lt;&lt;"00";
          string filename = ss.str();
          filename.append(".txt");
          ifs.open(filename.c_str());
          cout &lt;&lt; "Analyzing: " &lt;&lt; filename &lt;&lt; endl;
          string filename1 = "Result/";
          filename1.append(filename);
          ofs.open(filename1.c_str());
          string str;     
   for (int j=1; j&lt;=8; j++)
  {
     string s = IntToString(j);
          while (!ifs.eof()) {
              getline (ifs, str);
   int a = str.find("transmission number  for node "+s+" is :");
   if (a != -1) {
                  double TxEnergy = 0;
                  istringstream iss(str.substr(a+62));
                  iss &gt;&gt; TxEnergy;
                  maxTxEnergy = TxEnergy;
                                  if(maxTxEnergy&lt;TxEnergy)
                                  maxTxEnergy = TxEnergy; 
          }
  
    }
     TxE.push_back(maxTxEnergy);            
  
  }
  for (std::vector&lt;double&gt;::iterator it = TxE.begin(); it != TxE.end (); it++)
     {
  ofs &lt;&lt; "Full transmission Energy: " &lt;&lt; *it &lt;&lt; endl; 
      }          
          ifs.close();
          ofs.close();
      }
      return 0;
  }
  </code></pre>