@closed This is the input file. It is a .dat file with a list of integers
100
99
77
54
32
93
102
21
93
10
Second, my textbook shows me to do it in several ways, but this is one of them. What is incorrect about using .fail?
Also the code below purpose is to count the number of lines. It is being used to set the array size.
I tested the logic and it works.
The break down in my code was the summing of the elements in the array after they have been read in.
Using the same int variable(lineNum) for the input stream directly into the array was causing problems, as well as using "lineNum" itself as the variable being added into sum rather than the array.
I wonder if this was because lineNum already had data stored in it, and therefore reading into it again caused the issue.
@ closed >> Also in your post where you say "Thirdly" and are referencing the summing, you use a variable numLine in the cout statement. Is this a typo?
1 2 3 4 5 6 7 8
|
inFile >> lineNum;
while (!inFile.eof())
{
cout << setw(2) << lineNum++ << endl;
inFile >> lineNum;
}
|