c++ - This iterator is not iterating, whats wrong? -


problem iterator not iterating through loop. don't know why. #includes in header wont.

#include "neutronfilereader.h"  using namespace std ;  neutronfilereader::neutronfilereader() { }  list<vector<float> > neutronfilereader::spectrum(char* filename) {     ifstream fin(filename) ;     string binhi, binlo ;     list<vector<float> > neutronspectrum ;     list<vector<float> >::iterator ns ;     vector<float> energyprobability ;      while(!fin.eof())     {         getline(fin, binlo, ' ') ;                        //get binlo string         cout << "binlo: "<<binlo << endl ;         getline(fin, binhi, ' ') ;                        //get binhi string         cout<<"binhi: "<<binhi<<endl ;         energyprobability.push_back(atof(binhi.c_str())+(atof(binhi.c_str()) - atof(binlo.c_str()))/2) ;    //store middle of bin emission energy         getline(fin, binlo) ;                            //try not waste memory space         cout<<"prob: "<<binlo<<endl ;         energyprobability.push_back(atof(binlo.c_str())) ;    //store emnission probability         neutronspectrum.push_back(energyprobability) ;    //put vector in list         //cout<<neutronspectrum<<endl ;     }       for(ns = neutronspectrum.begin() ; ns != neutronspectrum.end() ; ns++)  //go through neutron spectrum     {         energyprobability = (*ns) ;         cout << "binval: " << energyprobability[0] << " " << "binprob: " << energyprobability[1] << endl ;         cout << "binval: " << (*ns)[0] << ", binprob: " << (*ns)[1] << ", memadd: " << &ns << endl ;          // print energy & prob screen     }      return neutronspectrum ; }  

anyway, here appreciated, have moved while loop, yes bug testing it's important bit of code. cheers guys, learning.

you're not clearing out energyprobability between input loops. (*ns)[0] therefore seeing redundantly stored values first input, ignoring new values in [2], [4] etc.. add energyprobability.clear() before reading more values it.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -