WarPhalange
I came across a snippet of code like this:
And I was told it will iterate through the vector "hits" 5 times. But by the looks of it, nothing is really being iterated. You have an initialization of "itr", but then it's never used.
So it looks like you get some value for hits and overwrite it on each successful iteration of the for() loop. Since it's printed out, you store it in a file so it doesn't matter if it's written over.
Am I correct here? That the line "vector<hit>::iterator itr;" is useless? Or is it used to print to file, i.e. "copy(hits.begin(),hits.end(),ostream_iterator<hit>(fout,"\n"));"?
Code:
protonPropagator pp;
vector<hit> hits;
vector<hit>::iterator itr;
for(int i=0;i<5;i++){
hits.clear();
//x,y,z,E,theta,phi
hits = pp.compute(startX,startY,startZ,startE,theta,phi);
if(hits.size()>0){
fout<<"startEvent"<<endl;
fout<<i<<" "<<hits.size()<<" "<<startX<<" "<<startY<<" "<<startZ<<" "<<startE<<" "<<theta<<" "<<phi<<endl;
copy(hits.begin(),hits.end(),ostream_iterator<hit>(fout,"\n"));
}else{
cerr<<"No hits in this event, skipping"<<endl;
}
}
And I was told it will iterate through the vector "hits" 5 times. But by the looks of it, nothing is really being iterated. You have an initialization of "itr", but then it's never used.
So it looks like you get some value for hits and overwrite it on each successful iteration of the for() loop. Since it's printed out, you store it in a file so it doesn't matter if it's written over.
Am I correct here? That the line "vector<hit>::iterator itr;" is useless? Or is it used to print to file, i.e. "copy(hits.begin(),hits.end(),ostream_iterator<hit>(fout,"\n"));"?