Efficient C++ Homework Help: Troubleshooting Infile Command Issues

  • Comp Sci
  • Thread starter giritrobbins
  • Start date
  • Tags
    C++ Homework
In summary, The person is having trouble with the infile command while trying to read in data from a text file, perform certain conditions on specific columns, and count up failures. They have tried using infile.close() and changing the value of the while loop, but it did not reset the counter. They also attempted reopening the file and using infile.clear(), but are unsure if they need to include a specific library for it to work.
  • #1
giritrobbins
8
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
  • #2
infile.clear();
 
  • #3
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.
 

1. How can I troubleshoot issues with the infile command in my C++ homework?

The first step in troubleshooting infile command issues is to carefully review your code to ensure that the infile command is being used correctly. Make sure that the infile is being opened in the right mode and that the correct file path is being used. If your code still does not work, try using a debugger to step through your program and identify where the issue is occurring.

2. Why is my infile command not reading the correct data?

One possible reason for this issue could be that the data in your input file is not formatted correctly. Make sure that the data in your input file matches the data type specified in your C++ code. If the data is in a different format, you may need to use functions such as stoi() or stod() to convert the data to the correct type.

3. How can I fix errors with the infile command not working?

If you are receiving errors related to the infile command, the first step is to carefully review the error message to identify the cause of the issue. Common errors include file not found, invalid file paths, or incorrect file permissions. Make sure that your input file is located in the correct directory and that your code has permission to access it.

4. What can I do if my infile command is only reading part of the input file?

In some cases, the infile command may only read part of the input file if there are errors or unexpected characters in the file. Make sure that your input file is properly formatted and does not contain any extra spaces or characters. Additionally, check that your code is correctly handling end-of-file conditions to ensure that all data is being read.

5. Are there any resources available for learning more about troubleshooting infile command issues?

Yes, there are many online resources available for learning more about troubleshooting infile command issues in C++. Some useful resources include forums, tutorials, and documentation from reputable sources such as C++ programming websites or university websites. Additionally, you may consider reaching out to your instructor or classmates for assistance or guidance.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
6K
Back
Top