ok this is a really basic question but I just can't seem to wrap my head around it. The basic syntax of how to open a file and check it and whatnot makes sense to me. But how the compiler reads from the file doesn't. For example if I have something like

Salesperson ID Model Code Count Sold New Line
8043 3 1 \n

Obviously each of these numbers have a specific function but I don't understand how to assign them each to the job they must do. I hope that makes sense.

You first have to declare variables to hold each of the numbers. Then just use the stream's >> operator to read from the file into the number

int SalespersonID, ModelCode, Count, Sold;
ifstream in("filename.txt");
while( in >> SalespersonID, >> ModelCode >> Count >> Sold)
{
    // blabla
}

You first have to declare variables to hold each of the numbers. Then just use the stream's >> operator to read from the file into the number

int SalespersonID, ModelCode, Count, Sold;
ifstream in("filename.txt");
while( in >> SalespersonID, >> ModelCode >> Count >> Sold)
{
    // blabla
}

Dude I could kiss you. I hope that works

Not enough information, could you elaborate on the problem?

basically take the model code and the count and calculate how much each salesperson sold then output to a report (text file)

I tried the following and it didn't work and I can't figure this out

double count, SalesID, modelCode
ifstream in;

while (!fin.eof())
{
fin >> count
sum+=count
}

That's basically what I did but what the problem is there like 60 rows and 4 columns in the file. I only want to tally numbers from one column. For example one column is amount sold. I only want to assign numbers from that column to "count". Anyone PLEASE help

It didn't work because you failed to follow the example I posted. Notice I did NOT use eof() because it doesn't work the way you think it works.

This article has been dead for over six months. Start a new discussion instead.