ECS 36B Lecture 16: Streams and Overloading
ECS 36B verified notes
16/26View all
Document Summary
Ecs 36b - lecture 16 - streams and operator overloading. Generalizes your program"s different sources of input characters. Creates a general place for user to put characters. Some common examples of streams are: files, the keyboard, terminal output, and sometimes even strings. To use a file stream, we must #include on top first. Note that file streams further have different types: for reading from a file, writing to a file, and doing both. When using streams, if you include the file name within the constructor, the file will automatically be opened. There will be no need to add a fopen() Also, to close a file one can call stream. close() or once that stream gets destroyed it automatically closes the file as well. It can be seen that with strings, manually opening and closing files are mostly emitted -- this prevents memory leaks/open files. Stream. isopen() will return true or false depending on if that file is opened or not.