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 7558119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:17:34+00:00 2026-05-30T12:17:34+00:00

vector<Flight> flights; while (!myReadFile.eof()) { flights.push_back(*(new Flight())); // read some info… } after the

  • 0
vector<Flight> flights;
while (!myReadFile.eof()) {
    flights.push_back(*(new Flight()));
// read some info...
}  

after the second loop the program crashes with the message:

“Unhandled exception at 0x776315de in cpi.exe: 0xC0000005: Access violation reading location 0xfeeefee2.”

How can I solve the problem?

edit:

vector<Flight> flights;
while (!myReadFile.eof()) {
    flights.push_back(Flight());
// read some info...
}

i tried this and still crash on the second loop

edit: full while

    int count = 0;
    myReadFile >> output;
    while (!myReadFile.eof()) {
        flights.push_back(Flight());
        flights[count].setFlightNum(atoi(output));

        myReadFile >> output;
        int x = atoi(output);
        flights[count].setStartX(x);
        myReadFile >> output;
        int y = atoi(output);
        flights[count].setStartY(y);

        count++;
        myReadFile >> output;
    }
  • 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-30T12:17:36+00:00Added an answer on May 30, 2026 at 12:17 pm

    You should stream directly into ints. If you have to read “tokens” then use a std::string but reading into a char array is always dangerous.

    You should also probably have code that will create a Flight object from a stream, albeit that I dislike the use of std::istream& operator>>(std::istream&, Flight& ), I find it “intrusive” and non-extensible. I prefer factories for this. However let’s write that function anyway:

    std::istream& operator>>(std::istream& is, Flight& flight )
    {
        int flightnum, x, y;
        if( is >> flightnum >> x >> y )
        {
           flight.setFlightNum( flightnum );
           flight.setStartX( x );
           flight.setStartY( y );
        }
        return is;
    }
    

    And now:

    std::vector< Flight > vec;
    
    while( myReadFile )
    {
        Flight flight;
        if( myReadFile >> flight )
           vec.push_back( flight );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

vector< int > vect; int *int_ptr = new int(10); vect.push_back( *int_ptr ); I under
vector<int> l; for(int i=0;i<10;i++){ l.push_back(i); } I want the vector to only be able
vector<int> l; for(int i=1;i<=10;i++){ l.push_back(i); } Now, for example, how do I change the
Vector <Double> x = new Vector<Double>(); Vector <Integer> y = new Vector <Integer>(); System.out.print(x.equals(y));
std::vector<float> someOp(void) { using namespace std; vector<float> results; // some operations done to results
vector<int> nums; nums.push_back(0); nums.push_back(1); nums.push_back(2); nums.push_back(3); vector<int>::iterator it = nums.begin(); it++; cout << it
std::vector sure is great, hey? I'm getting an EXC_BAD_ACCESS in using push_back to add
vector< vector< vector<int> > > myArray(5, vector< vector<int> >(4)); vector<int> testArray(); myArray[0][0].push_back(testArray); I don't
std::vector< boost::variant<std::string, int> > vec; std::string s1(abacus); int i1 = 42; vec.push_back(s1); vec.push_back(i1); std::cout
std::vector<int> my_ints; my_ints.push_back(1); my_ints.push_back(2); my_ints.push_back(3); my_ints.push_back(4); std::for_each(my_ints.begin(), my_ints.end(), std::cout.operator <<);

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.