C++ File Management | Set 3
21. Which operator is used to insert the data into file?
a) >>
b) <<
c) <
d) None of the above
Answer: B
Explanation: You can write information to a file from your program using the stream insertion operator <<.
22. Which is correct syntax?
a) myfile:open ("example.bin", ios::out);
b) myfile.open ("example.bin", ios::out);
c) myfile::open ("example.bin", ios::out);
d) myfile.open ("example.bin", ios:out);
Answer: B
Explanation: myfile.open ("example.bin", ios::out); is correct syntax.
23. ios::trunc is used for ?
a) If the file is opened for output operations and it already existed, no action is taken.
b) If the file is opened for output operations and it already existed, then a new copy is created.
c) If the file is opened for output operations and it already existed, its previous content is deleted and replaced by the new one.
d) None of the above
Answer: C
Explanation: No explanation is given for this question.
24. In fopen(), the open mode "wx" is sometimes preferred "w" because. i) Use of wx is more efficient. ii) If w is used, old contents of file are erased and a new empty file is created. When wx is used, fopen() returns NULL if file already exists.
a) Only i
b) Only ii
c) Both i & ii
d) None of the above
Answer: B
Explanation: No explanation is given for this question.
25. Which member function is used to determine whether the stream object is currently associated with a file?
a) is_open
b) Buf
c) String
d) None of the above
Answer: A
Explanation: The member function is_open can be used to determine whether the stream object is currently associated with a file.
26. getc() returns EOF when
a) End of files is reached
b) When getc() fails to read a character
c) Both A & B
d) None of the above
Answer: C
Explanation: No explanation is given for this question.
27. Which of the following is not a file opening mode ____ .
a) ios::ate
b) ios::nocreate
c) ios::noreplace
d) ios::truncate
Answer: D
Explanation: No explanation is given for this question.
28. Due to ios::trunc mode, the file is truncated to zero length.
a) True
b) False
Answer: A
Explanation: No explanation is given for this question.
29. If we have object from fstream class, then what is the default mode of opening the file?
a) ios::in|ios::out
b) ios::in|ios::out|ios::trunc
c) ios::in|ios::trunc
d) Default mode depends on compiler
Answer: D
Explanation: No explanation is given for this question.
30. What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main() {
char fine, course;
cout << "Enter a word: ";
fine = cin.get();
cin.sync();
course = cin.get();
cout << fine << endl;
cout << course << endl;
return 0;
}
a) course
b) fine
c) Returns fine 2 letter or number from the entered word
d) None of the mentioned
Answer: C
Explanation: In this program, We are using the sync function to return the fine two letters of the entered word.