Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
ifstream only reading one line of numbers from file
Post Flair (click to view more posts with a particular flair)
Post Body

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

void testDim(double bL, double bW, double bH, double jD, double jH);
void output(bool boolean, double bL, double bW, double bH, double jD, double jH);

ofstream outFile;

int main()
{
    double boxL, boxW, boxH, jarD, jarH;

    ifstream inFile;
    inFile.open("input.txt"); 


    while(inFile >> boxL >> boxW >> boxH >> jarD >> jarH)
    {
        testDim(boxL, boxW, boxH, jarD, jarH);
    }

    return 0;
}

void testDim(double bL, double bW, double bH, double jD, double jH)
{
    bool boolean;

    if(jH < (bH - 0.25))
    {
        if(jD < (bL - 0.25))
        {
            boolean = true;
        }
        else if(jD < (bW - 0.25))
        {
            boolean = true;
        }
    }
    else if(jD < (bH - 0.25))
    {
        if(jH < (bW - 0.25))
        {
            boolean = true;
        }
        else if(jH < (bL - 0.25))
        {
            boolean = true;
        }
    }
    else
    {
        boolean = false;
    }

    output(boolean, bL, bW, bH, jD, jH);
}

void output(bool boolean, double bL, double bW, double bH, double jD, double jH)
{
    outFile.open("output.txt");

    if(boolean == true)
    {
        outFile << bL << "\t" << bW << "\t" << bH << "\t" << jD << "\t" << jH << "\t" << "Yes" << endl;
    }
    else
    {
        outFile << bL << "\t" << bW << "\t" << bH << "\t" << jD << "\t" << jH << "\t" << "Yes" << endl;
    }
}

Summary: I have a file to read multiple lines of multiple doubles from. Then, those values have to be rewritten to another file, along with text saying some calculations were a success or not (outputting "yes" or "no" to the outFile). My problem is that either the inFile is not advancing to the next line after reading the last value from the first line, or my while loop is only iterating once, OR there's some weird buffer thing going on. My outFile has all the correct test data for the first line, but there's only one line when there should be multiple.

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,214
Link Karma
2,190
Comment Karma
6,915
Profile updated: 2 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago