wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++: Input & Output File (Set A)

Total questions: 10

Worksheet time: 8mins

Name
Class
Date
1.
Which of the following declares an input file stream variable?
a)
#include <fstream>
b)
ifstream fin;
c)
fin.open("nameoffile.txt");
d)
fin >> variable;
2.

What library is used to interact with external files?.

a)

<iostring>

b)

<iostream>

c)

<fstream>

d)

<sstring>

3.

What is the command to declare an input file stream?.

a)

ofstream

b)

ifstream

c)

sstream

d)

iostream

4.
In order, the three-step process of using a file in a C++ program involves:
a)
Insert a disk, open a file, remove the disk
b)
Create the file contents, close the file, name the file
c)
Open the file, read/write/save data, close the file
d)
Name the file, open the file, delete the file
5.
This data type can be used to create files and write information to them but cannot be used to read information from them.
a)
ofstream
b)
ifstream
c)
afstream
d)
outstream
6.
This data type can be used to create files, read data from them, and write data to them.
a)
ofstream
b)
iftream
c)
fstream
d)
stream
7.
Which of the following statements opens the file info.txt for both input and output?
a)
dataFile.open("info.txt", ios::in && ios::out);
b)
dataFile.open("info.txt", ios::in , ios::out);
c)
dataFile.open("info.txt", input || output);
d)
dataFile.open("info.txt", ios::in | ios::out);
8.
To set up a file to perform file I/O, you must declare:
a)
at least one variable, the contents of which will be written to the file
b)
one or more file stream objects
c)
a string object to store the file contents
d)
All of these
9.
ofstream, ifstream, and fstream are:
a)
header files
b)
libraries
c)
data types
d)
string arrays
10.
This data type can be used to create files and read information from them into memory.
a)
ofstream
b)
istream
c)
ifstream
d)
instream