Find the error(s) and show how to correct it (them) in each of the following.
a) File payables.txt referred to by ofstream object outPayable has not been opened.
outPayable << account << company << amount << endl;
b) The following statement should read a record from the file payables.txt. The if-stream object inPayable refers to this file, and istream object inReceivable refers to the file receivables.txt.
inReceivable >> account >> company >> amount;
c) The file tools.txt should be opened to add data to the file without discarding the current data.
ofstream outTools( "tools.txt", ios::out );
a) Error: The file payables.txt has not been opened before the attempt is made to out-put data to the stream.
Correction: Use ostream function open to open payables.txt for output.
b) Error: The incorrect istream object is being used to read a record from the file named payables.txt.
Correction: Use istream object inPayable to refer to payables.txt.
c) Error: The file’s contents are discarded because the file is opened for output
(ios::out).
Correction: To add data to the file, open the file either for updating (ios::ate) or
for appending (ios::app).
You might also like to view...
__________ are used to document a program and improve its readability.
Fill in the blank(s) with the appropriate word(s).
How does a surge protector protect against low-level surges?
A) It passes excess current through to the ground wire. B) It uses excess current to burn out a fuse. C) It passes excess current through a diffuser. D) It uses your home's circuit breaker panel.
What happens when you double-click the title bar?
A) The window is maximized or restored down. B) The window is closed. C) The window is minimized. D) A copy of the window is created.
Answer the following statement(s) true (T) or false (F)
The type of file system an OS uses determines how data is stored on the disk.