Programming II with C++ Quiz 5
To access files from a C++ program, you must #include ____.
<fstream>
In the statement template <class T>, what does T represent?
A generic data type that is used in a function template
Only one file stream object can be declared per C++ program.
False
Opening a file with the flags ios::in | ios::out will preserve the contents of the file if the file already exists.
False
The stream member function fail() can be used to determine whether the last operation performed on a stream was successful.
False
When you store data in a variable, it is automatically saved in a file.
False
File output may be formatted as screen output.
True
string objects cannot be stored to a binary file without further processing because they contain pointers.
True
An actual instance of a template function is created in memory when the compiler encounters ___.
a call to the template function
When a file is opened, the file stream object's "read position" is _____.
at the beginning of the file
ofstream, ifstream, and fstream are:
data types
The ___ member function reports when the end of a file has been found.
eof()
Which statement opens a file and links it to a file stream object?
file.open("Filename.txt")
All type parameters defined in a function template must appear at least once in the ___.
function parameter list
The member function, ___ , reads a single character from a file.
get
The state bit ___ is set when an attempted operation has failed.
ios::failbit
When used by itself, _____ causes a file's contents to be deleted if the file already exists.
ios::out
Outside of a C++ program, a file is identified by its ___. Inside a C++ program, a file is accessed through a ___.
name, file stream object
The member function ___ writes a single character to the file.
put
The ___ may be used to read information from a file.
stream extraction operator (>>)
The ____ may be used to write information to a file.
stream insertion operator <<
The beginning of a function template is marked by a ___.
template prefix
Write a template function that will take 3 numbers of a generic type and multiply them together and return the product.
template<class T> T multiply(T num1, T num2, T num3) { T answer; answer = num1 * num2 * num3; return answer; }
A(n) ____ is used in a function template to specify a generic data type.
type parameter
when the >> operator extracts information from a file, it expects to read data that are separated by _____.
whitespace