Comp Sci Efficient C++ Homework Help: Troubleshooting Infile Command Issues

  • Thread starter Thread starter giritrobbins
  • Start date Start date
  • Tags Tags
    C++ Homework
AI Thread Summary
The discussion focuses on troubleshooting issues with the infile command in C++ while attempting to read data from a text file. The user is experiencing problems with resetting the infile stream after closing it, as the end-of-file state persists. Attempts to modify the while loop condition and reopen the file have not resolved the issue. The user also mentions that infile.clear() is ineffective and questions whether additional libraries are needed beyond cstdlib, iostream, and fstream. The conversation highlights common challenges in file handling and stream management in C++.
giritrobbins
Messages
8
Reaction score
0

Homework Statement


Well I have to read in data from a text file test some conditions on certain columns and count up the failures. I am having a problem with the infile command, I have tried using infile.close(); but it does not seem to reset it.

while(infile>>y)
{
for(i;i<=(j/4);i++)
{
total=total+1;
if((2+4*i==total) && ((150>y) || (y>170)))
temp=temp+1;

if((3+4*i==total) && ((60>y)||(y>70)))
pressure=pressure+1;

if((4+4*1==total)&&((2>y)||(y>2.5)))
dwell=dwell+1;
}}

Homework Equations


n/a

The Attempt at a Solution



I have attemped infile.close(); but it did not seem to reset the counter saying it was the end of the file.

I also tried change the value of while(infile>>y) it was >>x before. Also I have tried reopening the file before this loop but it also does not seem to work.

Just to preface this there is a second loop before this that counts the total number of elements a number that I need and cannot nest within this loop.
 
Physics news on Phys.org
infile.clear();
 
infile.clear(); does not seem to work, is there a library that I need to include to use it. Right now I am using cstdlib, iostream, and fstream.
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...

Similar threads

Back
Top