File Handling Online Test

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Subramani Appavupillai
S
Subramani Appavupillai
Community Contributor
Quizzes Created: 1 | Total Attempts: 264
| Attempts: 264 | Questions: 15
Please wait...
Question 1 / 15
0 %
0/100
Score 0/100
1. By default, all the files in C++ are opened in _________ mode.

Explanation

In C++, by default, all files are opened in "Text" mode. This means that the file is treated as a text file, where characters are represented using their ASCII values. This mode allows for easy reading and writing of text data to and from the file. Other modes, such as "Binary" or "ASCII", may be used when dealing with non-textual data or specific encoding formats. However, in the absence of any specified mode, the default is "Text" mode.

Submit
Please wait...
About This Quiz
File Handling Quizzes & Trivia

This File Handling Online Test assesses knowledge on file operations in C++, covering file modes, stream types, and specific functions.

Personalize your quiz and earn a certificate with your name on it!
2. Which of the following is used to create a stream that performs both input and output operations?

Explanation

The correct answer is . This is because is a C++ library that allows for both input and output operations on files. It provides the functionality to create a stream that can read from and write to a file simultaneously. The other options, and , are used for either output or input operations respectively. is a library used for manipulating input/output formatting.

Submit
3.  What is the use of ios::trunc mode?

Explanation

The ios::trunc mode is used to truncate an existing file to zero. This means that when a file is opened in this mode, it will delete all the contents of the file and make it empty. This can be useful in situations where we want to start writing new data to a file from scratch, without any previous content.

Submit
4.  Pick out the correct statement.

Explanation

The correct statement is "you only need to write one function, and it will work with many different types." This means that by writing just one function, you can handle multiple types of inputs, making the code more efficient and reusable. It eliminates the need to write separate functions for each type, reducing code duplication and making the program easier to maintain.

Submit
5.  Which of the following is the default mode of the opening using the fstream class?

Explanation

The default mode of opening using the fstream class is ios::in|ios::out. This mode allows both input and output operations on the file.

Submit
6.  Which function allows you to set minimum width for the next input?

Explanation

The function setw() allows you to set the minimum width for the next input. This function is commonly used in C++ programming to specify the minimum number of characters to be written in the output. It is often used in combination with the

Submit
7.  Which header file is required to use file output operations?

Explanation

The header file is required to use file output operations. This header file provides the necessary functions and classes for writing data to files. It includes the ofstream class, which is used to create output file streams and perform output operations on them. By including this header file, we can access the necessary functionality for writing data to files in our program.

Submit
8.  What is a function template?

Explanation

A function template allows the creation of a function without specifying the exact type that it will operate on. This means that the function can be written in a generic way, allowing it to work with different types of data. It provides flexibility and reusability in code, as the same function template can be used with different types of arguments. The exact type is determined when the function is called, based on the argument provided.

Submit
9. Which function is used to reposition the file pointer?

Explanation

The seekg() function is used to reposition the file pointer. It allows us to move the file pointer to a specific position within the file, which can be useful when we want to read or write data at a specific location. The tellg() function is used to get the current position of the file pointer. The change() and getch() functions are not related to repositioning the file pointer.

Submit
10. Which of the following is used to move the file pointer to start of a file?

Explanation

The option "ios::beg" is used to move the file pointer to the start of a file. This is a flag in the ios class that represents the beginning of a file. By using this flag, the file pointer is set to the beginning of the file, allowing operations to be performed from the start.

Submit
11. Which of the following is not used to seek file pointer?

Explanation

The "ios:set" option is not used to seek the file pointer. The other options, "ios::cur", "ios::beg", and "ios::end" are used to seek the file pointer to the current position, the beginning of the file, and the end of the file, respectively. However, "ios:set" is not a valid option for seeking the file pointer.

Submit
12. Which function is used in C++ to get the current position of file pointer in a file?

Explanation

The tellp() function is used in C++ to get the current position of the file pointer in a file. It returns the current position as a streampos object, which represents the position in the stream. This function is typically used with file streams to determine the current position before performing any read or write operations.

Submit
13. Which is used to describe the function using placeholder types?

Explanation

Template type parameters are used to describe the function using placeholder types. These parameters allow the function to accept different data types as arguments, without the need to specify the exact type beforehand. By using template type parameters, the function becomes more flexible and can be used with various data types, providing a generic solution.

Submit
14. Which of the following is not used as a file opening mode?

Explanation

The option "ios:trunc" is not used as a file opening mode. This is because "ios:trunc" is not a valid file opening mode in C++ or any programming language. The correct file opening modes in C++ are "ios::in", "ios::out", "ios::app", "ios::ate", and "ios::binary".

Submit
15. What is the return type open() method?

Explanation

The return type of the open() method is bool, which stands for boolean. This means that the open() method will return either true or false. A boolean value is commonly used to indicate the success or failure of an operation. In the context of the open() method, it is likely that a true value would indicate that the file or resource was successfully opened, while a false value would indicate that the operation was unsuccessful.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Apr 28, 2020
    Quiz Created by
    Subramani Appavupillai
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
By default, all the files in C++ are opened in _________ mode.
Which of the following is used to create a stream that performs both...
 What is the use of ios::trunc mode?
 Pick out the correct statement.
 Which of the following is the default mode of the opening using the...
 Which function allows you to set minimum width for the next input?
 Which header file is required to use file output operations?
 What is a function template?
Which function is used to reposition the file pointer?
Which of the following is used to move the file pointer to start of a...
Which of the following is not used to seek file pointer?
Which function is used in C++ to get the current position of file...
Which is used to describe the function using placeholder types?
Which of the following is not used as a file opening mode?
What is the return type open() method?
Alert!

Advertisement