ENGR 101 Lecture 10: Streams and IO
Document Summary
A while loop can be used to repeatedly ask the user for input until it satisfies some criteria. A loop can be used to collect input until the user enters a special value, called a sentinel. Cin is an istream object (as well as ifstream) Cout is an ostream object (as well as ofstream) It is easier to work with files that are in the same directory where you run the program. To write output to a file, you use an ofstream object. If the file doesn"t exist, it will be created; If the file already exists, it will be overwritten. Remember to close the file once you are done using it: Will read an input rom a file names "words. in" Sometimes the program is unable to open a file for input because it doesn"t exist or a different program may be using it. Check whether the file opened successfully using fin. is_open()