Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

File Handling in C++

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

Files store data permanently in a/ an

a)

storage device.

b)

array.

c)

function.

d)

variable.

2.

A collection of characters that is written or read during file handling in C++ is called

a)

variable.

b)

stream.

c)

bits.

d)

numbers.

3.

Fstream library provides C++ programmers with ___________ classes for working with files

a)

Two

b)

Three

c)

Four

d)

Five

4.

A class which is used for reading information from data files is called

a)

ofstream

b)

ifstream

c)

fstream

d)

iostream

5.

A class which is capable of creating files, writing to files, reading from data files is called

a)

ofstream

b)

ifstream

c)

fstream

d)

iostream

6.

A class which is capable of creating files and writing information to files is called

a)

ofstream

b)

ifstream

c)

fstream

d)

iostream

7.

To perform file processing in C++, header files <iostream> and <fstream> must be included in your C++ source file.

a)

True

b)

False

8.

The output sent to the file is appended to it.

a)

ios :: ate

b)

ios :: in

c)

ios :: out

d)

ios :: app

e)

ios :: trunc

9.

It opens the file for the output then moves the read and write control to the file’s end.

a)

ios :: ate

b)

ios :: in

c)

ios :: out

d)

ios :: app

e)

ios :: trunc

10.

It opens the file for a read.

a)

ios :: ate

b)

ios :: in

c)

ios :: out

d)

ios :: app

e)

ios :: trunc

11.

It opens the file for a write.

a)

ios :: ate

b)

ios :: in

c)

ios :: out

d)

ios :: app

e)

ios :: trunc

12.

If a file exists, then it deletes the file content prior to its opening.

a)

ios :: ate

b)

ios :: in

c)

ios :: out

d)

ios :: app

e)

ios :: trunc

13.

Which of the following codes will close a file named as Sample?

a)

close(Sample);

b)

close.Sample();

c)

Sample.close();

d)

Sample(close);

14.

Which of the following codes will open a file named as Sample for reading and writing purposes?

a)

open("Sample.dat", ios::out | ios::in );

b)

open(ios::out | ios::in, "Sample.dat" );

c)

open("Sample.dat", ios::out && ios::in );

d)

open(ios::out && ios::in, "Sample.dat" );

15.

What is the code to open a file named as new_file in write mode and truncate it if it already exists?

a)

open("new_file.dat", <ios.out> | <ios.trunc> );

b)

open(<ios.out> | <ios.trunc>, "new_file.dat" );

c)

open(ios::out | ios::trunc, "new_file.dat" );

d)

open("new_file.dat", ios::out | ios::trunc );

16.

What is the code to open a file named as Sample and append output to the end of this file?

a)

Open("Sample.dat", "ios.app")

b)

Open("Sample.dat", ios::app)

c)

Open("ios.app", "Sample.dat")

d)

Open(ios::app, "Sample.dat")

17.

What is the code to open a file named as My_Data for reading data from it?

a)

Open("My_Data.dat", "ios::in")

b)

Open(My_Data.dat, "ios::in")

c)

Open("My_Data.dat", ios::in)

d)

Open(My_Data.dat, ios::in)

18.

What is the code to open a file named as Old_Data for writing data to it?

a)

Open("My_Data.dat", ios::out)

b)

Open("My_Data.dat", ios $$ out)

c)

Open("My_Data.dat", ios..out)

d)

Open("My_Data.dat", <iosout>)

19.

What is the code to open a file named as Sample and remove all the previous content stored in the file?

a)

Open(ios::trunc, "Sample.dat")

b)

Open("Sample.dat", "ios::trunc")

c)

Open("ios::trunc", "Sample.dat")

d)

Open("Sample.dat", ios::trunc)

20.

What is the code to open a file named as Updated_Data for output and move the read/write control to the end of the file?

a)

Open("Updated_Data.dat" | ios::ate)

b)

Open("Updated_Data.dat", ios::ate)

c)

Open("Updated_Data.dat" && ios::ate)

d)

Open("Updated_Data.dat" $$ ios::ate)