ExamVeda
Login
Home
11
How do you check if the end of a file has been reached in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
12
Which function is used to get the current position of the file pointer in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
13
What is the purpose of the ios::app flag in C++ file handling?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
14
Which function is used to check if a file exists in C++?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
15
How do you create a new file in C++?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
16
What is the function used to create a new file in C++?
Discuss
Answer & Solution
Answer: Option D
Solution:
The correct answer is D: ofstream file()
Let's break down why:

Option A: create() - There isn't a standard C++ function called create() specifically for file creation.

Option B: newFile() - Similarly, newFile() is not a built-in C++ function for file handling.

Option C: fopen() - fopen() is a C function for file input/output, and while it *can* be used in C++, it's more common and idiomatic to use C++'s file stream classes.
fopen() also requires you to specify a mode (like "w" for write) which determines if you want to create the file, overwrite it, or append to it. It's generally less type-safe than C++ streams.

Option D: ofstream file() - This is the C++ way to create a new file. ofstream is a class from the C++ standard library designed for output file streams.
By creating an object of type ofstream (e.g., ofstream file;), you can automatically create a new file or open an existing one for writing (if the file doesn't exist, it will be created). You can then use the file object to write data to the file.
For Example : ofstream myFile("filename.txt"); will create a file named "filename.txt" or overwrite if it already exist .
17
Which file mode is used to open a file for reading only in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
18
How do you check if a file exists before opening it in C++?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
19
Which of the following is not a file stream class in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
20
What is the function used to write data to a file in C++?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board