8.2. File Input and Output

Image

The fstream header defines three types to support file IO: ifstream to read from a given file, ofstream to write to a given file, and fstream , which reads and writes a given file. In § 17.5.3 (p. 763) we’ll describe how to use the same file for both input and output.

These types provide the same operations as those we have previously used on the objects cin and cout. In particular, we can use the IO operators (<< and >>) to read and write files, we can use getline3.2.2, p. 87) to read an ifstream, and the material covered in § 8.1 (p. 310) applies to these types.

In addition to the behavior that they inherit from the iostream types, the types defined in fstream add members to manage the file associated with the stream. These operations, listed in Table 8.3, can be called on objects of fstream, ifstream, or ofstream but not on the other IO types.

Table 8.3. fstream-Specific Operations

Image
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset