Deck 12: Advanced File Operations
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/38
Play
Full screen (f)
Deck 12: Advanced File Operations
1
An alternative to using the open member function is to use the file stream object declaration itself to open the file. For example:
fstream DataFile("names.dat", ios:
:
in | ios:
:
out);
fstream DataFile("names.dat", ios:
:
in | ios:
:
out);
True
2
To write to a file, you use the file_write function.
False
3
Which of the following is the data type that 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
E) None of these
A) ofstream
B) ifstream
C) afstream
D) outstream
E) None of these
A
4
Which of the following statements opens a file named 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);
E) None of these
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);
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
5
Data stored __________ disappears once the program stops running or the computer is powered down.
A) on a CD
B) in RAM
C) on a flash drive
D) on the disk drive
E) None of these
A) on a CD
B) in RAM
C) on a flash drive
D) on the disk drive
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
6
When passing a file stream object to a function, you should always pass it by reference.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
7
When you store data in a variable, it is automatically saved in a file.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
8
If a file already exists, you can open it with the flags ios::in | ios::out to preserve its contents.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
9
The ios::hardfail bit is set when an unrecoverable error occurs.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following statements opens a file and links it to a file stream object?
A) open(aFile) = link(anObject);
B) file.open("filename.txt");
C) linkstream("filename.txt");
D) link(open("filename.txt");
E) None of these
A) open(aFile) = link(anObject);
B) file.open("filename.txt");
C) linkstream("filename.txt");
D) link(open("filename.txt");
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following is the data type that can be used to create files, read data from them, and write data to them?
A) ofstream
B) ifstream
C) fstream
D) stream
E) None of these
A) ofstream
B) ifstream
C) fstream
D) stream
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
12
Only one file stream object can be declared per C++ program.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
13
The ios::out flag causes the file's existing contents to be deleted if the file already exists.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
14
By default, files are opened in binary mode.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
15
The setprecision manipulator cannot be used to format data written to a file.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
16
When data is read from a file, it is automatically stored in a variable.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
17
In order, the three-step process of using a file in a C++ program involves
A) insert a disk, open the 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
E) None of these
A) insert a disk, open the 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
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
18
When used by itself, the ios::app flag causes the file's existing contents to be deleted if the file already exists.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
19
File output may be formatted the same way as console screen output.
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following is the state bit that can be tested to see if the end of an input stream is encountered?
A) ios::eof
B) ios::eofbit
C) ios::failbit
D) ios::badbit
E) None of these
A) ios::eof
B) ios::eofbit
C) ios::failbit
D) ios::badbit
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following data types can be used to create files and read information from them into memory?
A) ofstream
B) istream
C) ifstream
D) instream
E) None of these
A) ofstream
B) istream
C) ifstream
D) instream
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following access flags, when used by itself, causes a file's contents to be deleted if the file already exists?
A) ios::app
B) ios::in
C) ios::out
D) Any of these
E) None of these
A) ios::app
B) ios::in
C) ios::out
D) Any of these
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following means accessing information from a file non-sequentially?
A) linear access
B) incremented acces
C) random access
D) protected access
E) None of these
A) linear access
B) incremented acces
C) random access
D) protected access
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
24
Which statement opens a file in such a way that information will only be written to the end of the file?
A) dataFile(open.append("info.dat");
B) dataFile.open("info.dat", ios::out | ios::app);
C) datFile.open = "c:\\info.dat" ios::append;
D) open(dataFile.append);
E) None of these
A) dataFile(open.append("info.dat");
B) dataFile.open("info.dat", ios::out | ios::app);
C) datFile.open = "c:\\info.dat" ios::append;
D) open(dataFile.append);
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
25
Closing a file causes any unsaved information still held in the file buffer to be
A) saved to the file
B) deleted
C) retained in the buffer for safekeeping
D) duplicated
E) None of these
A) saved to the file
B) deleted
C) retained in the buffer for safekeeping
D) duplicated
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is the member function that can be used to store binary data to a file?
A) binary.out
B) write
C) put <<
D) dataout(binary)
E) None of these
A) binary.out
B) write
C) put <<
D) dataout(binary)
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
27
All stream objects have __________ which indicate the position of the stream.
A) error state bits
B) condition statements
C) markers
D) intrinsic error messages
E) None of these
A) error state bits
B) condition statements
C) markers
D) intrinsic error messages
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
28
The __________ marker is the character that marks the end of a file and is automatically written when the file is closed.
A) End Of File (EOF)
B) No More Data (NMD)
C) Data Stream Close (DSC)
D) Data Read Stop (DRS)
E) None of these
A) End Of File (EOF)
B) No More Data (NMD)
C) Data Stream Close (DSC)
D) Data Read Stop (DRS)
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
29
When a file is opened, the file stream object's "read position" is
A) at the end of the file
B) at the beginning of the file
C) nonexistent until the programmer declares it
D) in the middle of the file
E) None of these
A) at the end of the file
B) at the beginning of the file
C) nonexistent until the programmer declares it
D) in the middle of the file
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following is the state bit that is set when an attempted operation fails?
A) ios::failbit
B) ios::badbit
C) ios::hardfail
D) ios::goodbit
E) None of these
A) ios::failbit
B) ios::badbit
C) ios::hardfail
D) ios::goodbit
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is the directive you must use to access files from a C++ program?
A) #include
B) #include
C) #include
D) #include
E) None of these
A) #include
B) #include
C) #include
D) #include
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
32
What is true about the following statement?
Out)open("values.dat", ios:
:
App);
A) If the file already exists, its contents are preserved and all output is written to the end of the file.
B) If the file already exists, it should be replaced with a new copy of values.dat.
C) If the file already exists, it can be opened but not modified.
D) None of these
Out)open("values.dat", ios:
:
App);
A) If the file already exists, its contents are preserved and all output is written to the end of the file.
B) If the file already exists, it should be replaced with a new copy of values.dat.
C) If the file already exists, it can be opened but not modified.
D) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
33
To set up a file to perform 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
E) None of these
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
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
34
Which of the following is the member function that reads a single character from a file?
A) read
B) get
C) put
D) input
E) None of these
A) read
B) get
C) put
D) input
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
35
Outside of a C++ program, a file is identified by its __________while inside a C++ program, a file is identified by a(n) __________.
A) file number, file name
B) file name, file number
C) name, address
D) name, file stream object
E) None of these
A) file number, file name
B) file name, file number
C) name, address
D) name, file stream object
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
36
ofstream, ifstream, and fstream are
A) header files
B) libraries
C) data types
D) string arrays
E) None of these
A) header files
B) libraries
C) data types
D) string arrays
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following is the member function that writes a single character to a file?
A) get
B) write
C) put
D) insert
E) None of these
A) get
B) write
C) put
D) insert
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck
38
The end-of-file marker is automatically written
A) when a file is opened with ios::eof
B) when a file is opened with ios::app
C) when a file is closed
D) when the program ends
E) None of these
A) when a file is opened with ios::eof
B) when a file is opened with ios::app
C) when a file is closed
D) when the program ends
E) None of these
Unlock Deck
Unlock for access to all 38 flashcards in this deck.
Unlock Deck
k this deck