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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:43:56+00:00 2026-06-12T22:43:56+00:00

So basically, I’m writing a program to take in a set of data and

  • 0

So basically, I’m writing a program to take in a set of data and input the results into a vector of structures. However, the issue I am having is with the end of file flag never being set in my while loop located in the main function

int main()
{
ifstream machineRecords;
machineRecords.open ("records.txt");
if (machineRecords.fail())
{
    cout << "Failed to open \'records.txt\' please make sure it is in the same directory as the executable.";
    exit(1);
}

char tempChar;
string record;
do
{
    int LINE = 0;
    for (int x = 0; x <= 11; x++)
    {
        cout << "Begin storing characters in record" << endl;
        do  //Stores one character at a time into the node string until it discovers the end of the node
        {
            tempChar = machineRecords.get();
            record += tempChar;
            cout << "||" << tempChar << endl;
            //_getch();
        } while (tempChar != '|' && tempChar != '\n');
        eraseCharFromString(record, '|');       //Removes ending tag character
        eraseCharFromString(record, '\n');  //Removes any sneaky newline characters

        cout << "Record: " << record << endl;

        switch(x)
        {
            case 0:
                machines[LINE].idNumber = atoi(record.c_str());
                break;
            case 1:
                machines[LINE].description = record;
                break;
            case 2:
                machines[LINE].purchaseDate.month = atoi(record.c_str());
                break;
            case 3:
                machines[LINE].purchaseDate.day = atoi(record.c_str());
                break;
            case 4:
                machines[LINE].purchaseDate.year = atoi(record.c_str());
                break;
            case 5:
                machines[LINE].cost = atof(record.c_str());
                break;
            case 6:
                machines[LINE].history.failRate = atof(record.c_str());
                break;
            case 7:
                machines[LINE].history.downDays = atoi(record.c_str());
                break;
            case 8:
                machines[LINE].history.lastServiced.month = atoi(record.c_str());
                break;
            case 9:
                machines[LINE].history.lastServiced.day = atoi(record.c_str());
                break;
            case 10:
                machines[LINE].history.lastServiced.year = atoi(record.c_str());
                break;
        }
        record = "";
        _getch();
    }

    tempChar = machineRecords.get();
    if (machineRecords.fail())
    {
        cout << "DONE" << endl;
        break;
    }
    else
    {
        machineRecords.putback(tempChar);
    }

    ++LINE;
    _getch();
} while (!machineRecords.eof());    //While not at the end of the file

recordFromLastDate(1999);

machineRecords.close();
_getch();
return 0;
}

Any formatting errors are SO’s problem.

But anyway, even when I try to test read another character after each line, it simply will not trigger the eof flag. I really have no clue why not.

Unfortunately I don’t have the time to rewrite too much the code because of a ton of other projects for midterms, but I really wanted to know if I was doing something completely wrong or what.

  • 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-06-12T22:44:00+00:00Added an answer on June 12, 2026 at 10:44 pm

    EOF only set when you read a character beyond end of file, so it is wise to think EOF will be set after machineRecords.get() that you never test its return value, so subsequent reads will set failure bit of the stream and EOF will be ignored. just test result of machineRecords.get() with -1 to catch EOF or error before continue

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

Sidebar

Related Questions

Basically I have a large set of data in excel, and I was wondering
Basically this is a program which I take a text file with some code
Basically I have converted a tab delimited txt file into a list containing a
Basically I am writing a simple bit of code to increment every one second
Basically from a database I am getting data that is formatted like this nameofproject101
Basically, I want to get and display the data of a midi note (the
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I
Basically I want to know how to set center alignment for a cell using
Basically, when I type these commands in the terminal by hand, the sift program

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.