Presentation is loading. Please wait.

Presentation is loading. Please wait.

Start. Error Checking 03/07/11 Check for Opening Error –streams4.2/low_price.cpp.fail() true when an error has occurred –Stream function exit(1) stops.

Similar presentations


Presentation on theme: "Start. Error Checking 03/07/11 Check for Opening Error –streams4.2/low_price.cpp.fail() true when an error has occurred –Stream function exit(1) stops."— Presentation transcript:

1 Start

2 Error Checking 03/07/11

3 Check for Opening Error –streams4.2/low_price.cpp.fail() true when an error has occurred –Stream function exit(1) stops execution –Must #include –Abnormal exit, 1 for error, 0 for no error Permission on the file is set so that I can't read it.

4 Input Stream Errors –.fail True after reading bad data Can prevent runtime error –.clear Clears error condition Program can then continue –ch4/streams4.2/btu.cpp

5 Checking for End-of-Data –Want to read in a list of weight of car loads of coal on a train. –Want to add them up. –Don't know exactly how many numbers in the file, coal.txt. –Want an alternative to sentinels.

6 Checking for End-of-Data –Algorithm: sum = 0 Input tons from stream While(not end-of-file)‏ » Add tons to train_load » Input tons from stream Output train_load.

7 Checking for End-of-Data –while(!wgt_in.eof( ))‏ eof returns true when attempt to read eof character is made. –In streams4.2 coal2.cpp and coal.txt

8 On Your Own –Modify ave.cpp so that I don't have to put a sentinel in the file.

9 Reading –Chapter 5 pp. 169-180


Download ppt "Start. Error Checking 03/07/11 Check for Opening Error –streams4.2/low_price.cpp.fail() true when an error has occurred –Stream function exit(1) stops."

Similar presentations


Ads by Google