Deck 13: Advanced File and Io 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
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
Play
Full screen (f)
Deck 13: Advanced File and Io Operations
1
The ________ member function reports when the end of a file has been found.
A) end()
B) stop()
C) done()
D) eof()
E) None of the above
A) end()
B) stop()
C) done()
D) eof()
E) None of the above
D
2
An alternative to using the open member function is to use the file stream object declaration itself to open the file.
Example: fstream dataFile("names.dat",ios::in|ios::out);
Example: fstream dataFile("names.dat",ios::in|ios::out);
True
3
The read and write member functions of fstream objects can only work with buffers specified by pointers to char.
True
4
The operation of moving to a particular location in an input file is accomplished through
A) the seekg member function.
B) the seekp member function.
C) the move member function.
D) the locate member function.
E) None of the above
A) the seekg member function.
B) the seekp member function.
C) the move member function.
D) the locate member function.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
The stream member function fail() can be used to determine whether the last operation performed on a stream was successful.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
The statement dataFile.close();
A) is illegal in C++.
B) needs a file name argument to execute correctly.
C) closes a file.
D) is legal but risks losing valuable data.
E) None of the above
A) is illegal in C++.
B) needs a file name argument to execute correctly.
C) closes a file.
D) is legal but risks losing valuable data.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
The state bit, ________, can be tested to see if the end of an input stream has been encountered.
A) ios::eof
B) ios::eofbit
C) ios::failbit
D) ios::badbit
E) None of the above
A) ios::eof
B) ios::eofbit
C) ios::failbit
D) ios::badbit
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
The ________ may be used to write information to a file.
A) cout object
B) pen object
C) stream insertion operator <<
D) fileWrite() function
E) None of the above
A) cout object
B) pen object
C) stream insertion operator <<
D) fileWrite() function
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
The ________ function can be used to store binary data to a file.
A) binary.out
B) write
C) put
D) dataout(binary)
E) None of the above
A) binary.out
B) write
C) put
D) dataout(binary)
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
The member function, ________, reads a single character from a file.
A) read
B) get
C) put
D) input
E) None of the above
A) read
B) get
C) put
D) input
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
string objects cannot be stored to a binary file without further processing because they contain pointers.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
The ________ data type can be used to create files and write information to them.
A) ofstream
B) ifstream
C) istream
D) ostream
E) None of the above
A) ofstream
B) ifstream
C) istream
D) ostream
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
A file ________ is a small holding section of memory that file-bound information is first written to.
A) name
B) number
C) buffer
D) segment
E) None of the above
A) name
B) number
C) buffer
D) segment
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
Data stored ________ is lost when the computer is powered down.
A) on CD ROM
B) in RAM
C) on a backup tape
D) on the hard disk
E) None of the above
A) on CD ROM
B) in RAM
C) on a backup tape
D) on the hard disk
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
Only one file stream object can be declared per C++ program.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
File output may be formatted the same way as screen output.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
When you store data in a variable, it is automatically saved in a file.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
When you assign a name to a file, the operating system identifies the file by that name.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
The process of writing in-memory objects to a file so that the object can later be read back into memory
A) requires the use of specialized convert constructors.
B) is called serialization.
C) requires special operation system support.
D) is called deserialization.
E) None of the above
A) requires the use of specialized convert constructors.
B) is called serialization.
C) requires special operation system support.
D) is called deserialization.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
Which statement 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 the above
A) open(AFile) = link(anObject);
B) file.open("filename.txt");
C) linkstream("filename.txt");
D) link(open(filename.txt"));
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
Closing a file causes any buffered information to be
A) saved to the file.
B) deleted.
C) stored in a buffer for safekeeping.
D) duplicated.
E) None of the above
A) saved to the file.
B) deleted.
C) stored in a buffer for safekeeping.
D) duplicated.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
ofstream, ifstream, and fstream are
A) header files.
B) libraries.
C) data types.
D) string arrays.
E) None of the above
A) header files.
B) libraries.
C) data types.
D) string arrays.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
The ios::hardfail bit is set when an unrecoverable error occurs.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
When the >> operator extracts information from a file, it expects to read data that are separated by
A) commas.
B) tabs.
C) whitespace.
D) semicolons.
E) None of the above
A) commas.
B) tabs.
C) whitespace.
D) semicolons.
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
The operating system records the information that tracks the end of the file
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 the above
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 the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
When a file is opened for reading, 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 the above
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 the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
Opening a file with the flags ios::in | ios::out will preserve the contents of the file if the file already exists.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
The state bit ________ is set when an attempted operation has failed.
A) ios::failbit
B) ios::badbit
C) ios::hardfail
D) ios::goodbit
E) None of the above
A) ios::failbit
B) ios::badbit
C) ios::hardfail
D) ios::goodbit
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
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) All of the above
E) None of the above
A) ios:app
B) ios::in
C) ios::out
D) All of the above
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
Outside of a C++ program, a file is identified by its ________. Inside a C++ program, a file is accessed through a ________.
A) file number, file name
B) file name, file number
C) name, address
D) name, file stream object
E) None of the above
A) file number, file name
B) file name, file number
C) name, address
D) name, file stream object
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
A file must be ________ before data can be written to or read from it.
A) closed
B) opened
C) declared
D) initialized
E) None of the above
A) closed
B) opened
C) declared
D) initialized
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
The member function ________ writes a single character to a file.
A) get
B) write
C) put
D) insert
E) None of the above
A) get
B) write
C) put
D) insert
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
The ________ data type can be used to connect to files and read information from them into memory.
A) ofstream
B) istream
C) ifstream
D) instream
E) None of the above
A) ofstream
B) istream
C) ifstream
D) instream
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
All stream objects have ________ that indicate the condition of the stream.
A) error state bits
B) condition statements
C) markers
D) intrinsic error messages
E) None of the above
A) error state bits
B) condition statements
C) markers
D) intrinsic error messages
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
To access files from a C++ program, you must #include
A).
B).
C).
D).
E) None of the above
A)
B)
C)
D)
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
To write to a binary file, you can use the write() member function of an ofstream object.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
To set up a file to perform file I/O, you must declare
A) at least one variable to write to the file.
B) one or more file stream objects.
C) a string array to store the file contents.
D) All of the above
E) None of the above
A) at least one variable to write to the file.
B) one or more file stream objects.
C) a string array to store the file contents.
D) All of the above
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
The ________ may be used to read information from a file.
A) cout object
B) the stream insertion operator
C) file.in macro
D) stream extraction operator
E) None of the above
A) cout object
B) the stream insertion operator
C) file.in macro
D) stream extraction operator
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
Which statement opens a file in such a way that information will only be written to its end?
A) dataFile(open.append("info.dat");
B) dataFile.open("info.dat", ios::out | ios::app);
C) dataFile.open = "C:\\info.dat" ios:append;
D) open(dataFile.append);
E) None of the above
A) dataFile(open.append("info.dat");
B) dataFile.open("info.dat", ios::out | ios::app);
C) dataFile.open = "C:\\info.dat" ios:append;
D) open(dataFile.append);
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
The term ________ means non-sequentially accessing information in a file.
A) cin.getline
B) cin.getrandom
C) random access
D) read.randomly
E) None of the above
A) cin.getline
B) cin.getrandom
C) random access
D) read.randomly
E) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck