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 nonprinting lines used to precisely align objects on a slide
Fill in the blank(s) with correct word
Given the class definition,
``` class A { public: A(){} A(int x, char y):xx(x), yy(y) {} // other members private: int xx; char yy; ``` Tell which definition below is legal. If legal, tell whether it is a definition of an object of class A. If the definition is a legal and defines a class A object, tell which constructor is called for each of the following definitions. Identify the constructor like this: If the constructor for class A with two int arguments is called, respond with A(int, int). a)``` A x(2, ‘A’); ``` b)``` A x; ``` c)``` A x(1); ``` e)``` A x( ); ```