11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

318Part V: Optional FeaturesAll attempts to output to an ofstream object that has an error have no effectif my.bad() is true.This last paragraph is meant quite literally — no output is possible as long asthe internal error state is non-zero. The program won’t even try until you callclear() to clear the error flags.The destructor for class ofstream automatically closes the file. In the precedingexample, the file was closed when the function exited.Class ifstream works much the same way for input, as the following exampledemonstrates:// StreamInput - simple input from a file using fstream#include #include using namespace std;ifstream* openFile(){ifstream* pFileStream = 0;for(;;){// open the file specified by the userchar fileName[80];cout good()){break;}cerr

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!