Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3459436
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:06:21+00:00 2026-05-18T10:06:21+00:00

I have bug checked this code considerably now and made sure I am outputting

  • 0

I have bug checked this code considerably now and made sure I am outputting the ‘correct’ things to outline the problem. The iterator never points at the list at all, but another bunch of addresses which happily contain the correct data.

I have two questions:

1 = given the form of the couts, am I outputting the correct items to investigate why this loop is not exiting ;

2 = if(1) then what is going on to produce this output and do you have any advice to further my pointer knowledge (I have used this for loop format many times before and this as never happened ;

/questions

code :

#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 ;
 }

and here is the output:

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

thanks much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:06:22+00:00Added an answer on May 18, 2026 at 10:06 am

    Ok it seems to be working ok then (according to the last example).

    It reaches the last element and then stops (the ones with the while never reach the last element because they fail the condition on the last element).

    The key here is that .end() and .back() point to different things so that difference of addresses is to be expected.

    .back() references the last element of the list.
    .end() references a past-last-element that serves to stop the cycle ONLY after the last element was handled (as opposed to what happens with the:

    while(&(*nS) != lastListElement) {
    /*...*
    }
    

    that results in the cycle stopping BEFORE analyzing the last element.

    From what I could gather your only problem was with the output of the addresses right? Or is the cycle not exiting where it is supposed to?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a interest in a reported bug which Microsoft have made available a
I have the following code that shows either a bug or a misunderstanding on
This is a registered bug ( Bug ID: 6515708 ) but does anyone have
I have this form in my view: <!-- Bug (extra 'i') right here-----------v -->
We're currently running with php 5.2.5. We have now encountered a bug that creates
I have a few lines of code where I use this function, but it
I may have found a Subversion bug, and I would like to make sure
I have strange bug with showing image in silverlight. The problem to show list
I have had a bug recently that only manifested itself when the library was
EDIT: I have submitted a bug report and Microsoft have acknowledge that it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.