Skip to main content

Section 6.10 Summary & Reading Questions

  1. File handling in C++ uses stream similar to cout and cin in <iosteam> library but is <fstream> for file stream.
  2. ifstream in_stream creates an input stream object, in_stream, that can be used to input text from a file to C++.
  3. ofstream out_stream creates an output stream object,out_steam, that can be used to write text from C++ to a file.
  4. End-of-File or .eof() is a method for the instance variables of fstream, input and output stream objects, and can be used to carry out a task until a file has ended or do some task after a file has ended.

Reading Questions Reading Questions

1.

Which of the following are libraries for C++ input and output? (Choose all that are true.)
  • fstream
  • Yes, fstream is library for handling file input and output.
  • ifstream
  • No, ifstream is an object type for handling input.
  • ofstream
  • No, ofstream is an object type for handling output.
  • iostream
  • Yes, iostream is a library for handling console input and output.

2.

3.

Fill in the blank with the value of inputn when the following code runs.
#include <fstream>
            #include <cstdlib>
            #include <iostream>
            using namespace std;
            
            main(){
              ifstream in_stream;
              ofstream out_stream;
              int inputn;
            
              out_stream.open("anotherFile.txt");
              out_stream << 25;
              out_stream << 15 << endl;
              out_stream << 101 << endl;
            
              in_stream.open("anotherFile.txt");
              in_stream >> inputn;
              cout << inputn;
              in_stream >> inputn;
            }

4.

You have attempted 1 of 4 activities on this page.