私はこのコードをかなりよくチェックして、問題の概要を示す正しいものを出力していることを確認しました。イテレータはリストを一度も指すことはありませんが、うまくいけば正しいデータが含まれている別のアドレスの束です。イテレータの問題が続きます
私は2つの質問があります。
1 = coutsの形与えられたが、私はこのループは出ていない理由を調査するために、正しい項目を出力しています。
2 =(1)その後、何この出力を生成するために起こっているとあなたは私のポインタの知識を促進するために何かアドバイスはあります(私は前にループ形式のために何回もこれを使用しており、これが起こっていないように決してならば、
/質問
コード:
#include "neutronFileReader.h"
using namespace std ;
neutronFileReader::neutronFileReader()
{
}
list<vector<float> > neutronFileReader::spectrum(char* filename)
{
ofstream addresses ;
addresses.open("adresses.txt") ;
ifstream fin(filename) ;
string binhi, binlo ;
list<vector<float> > neutronSpectrum ;
list<vector<float> >::iterator nS ;
vector<float> EnergyProbability ;
while(!fin.eof())
{
EnergyProbability.clear() ;
getline(fin, binlo, ' ') ; //get the binlo string
getline(fin, binhi, ' ') ; //get the binhi string
EnergyProbability.push_back(atof(binhi.c_str())+(atof(binhi.c_str()) - atof(binlo.c_str()))/2) ; //store middle of bin as emission Energy
getline(fin, binlo) ; //try not to waste memory space
EnergyProbability.push_back(atof(binlo.c_str())) ; //store emnission probability
neutronSpectrum.push_back(EnergyProbability) ; //put the vector in the list
}
for(nS = neutronSpectrum.begin() ; nS != neutronSpectrum.end() ; nS++) //go through the neutron spectrum
{
EnergyProbability = (*nS) ;
addresses << &neutronSpectrum.begin() << " : " << &(*nS) << " : " << &neutronSpectrum.end() << endl ; // print energy & prob to screen
cout << &neutronSpectrum.begin() << " : " << &(*nS) << " : " << &neutronSpectrum.end() << endl ;
}
return neutronSpectrum ;
}
、ここでは出力されます:
0x28fbc4 : 0x510c38 : 0x28fbc0
0x28fbc4 : 0x510c58 : 0x28fbc0
0x28fbc4 : 0x510c78 : 0x28fbc0
0x28fbc4 : 0x510c98 : 0x28fbc0
0x28fbc4 : 0x510cb8 : 0x28fbc0
0x28fbc4 : 0x510cd8 : 0x28fbc0
0x28fbc4 : 0x510cf8 : 0x28fbc0
0x28fbc4 : 0x510d18 : 0x28fbc0
0x28fbc4 : 0x510d38 : 0x28fbc0
0x28fbc4 : 0x510d58 : 0x28fbc0
0x28fbc4 : 0x510d78 : 0x28fbc0
0x28fbc4 : 0x510d98 : 0x28fbc0
0x28fbc4 : 0x510db8 : 0x28fbc0
0x28fbc4 : 0x510dd8 : 0x28fbc0
0x28fbc4 : 0x510df8 : 0x28fbc0
0x28fbc4 : 0x510e18 : 0x28fbc0
0x28fbc4 : 0x510e38 : 0x28fbc0
0x28fbc4 : 0x510e58 : 0x28fbc0
0x28fbc4 : 0x510e78 : 0x28fbc0
0x28fbc4 : 0x510e98 : 0x28fbc0
0x28fbc4 : 0x510eb8 : 0x28fbc0
ありがとうございました。
それはあなたの助けによるものではなく、実際には1つの投稿の後に正しく動作していました。 *恥ずかしがり屋。しかし、この前後でイテレータの理解が大幅に向上しましたので、非常に反抗してくれてありがとう、あなたの時間を無駄にしてしまいました。あなたもそれから何かを得ることを望む! – morb
本当に!私がSTLコンテナ(地獄、私がC++を使いこなした最後の時間)を混乱させた最後の時間は、2年前だったので、リフレッシャーとして役立った。私は助けになることができてうれしい! – AlexJF