Write a function that will copy the contents of file in.dat to the file out.dat. Check for successful file opening of both in.dat and out.dat. The loop that actually does the copy should terminate on end of file.
What will be an ideal response?
Note: in.get() is used because it will do both of two necessary things: First, it will not ignore blanks. Second, it will return a 0 (false) when end of file is reached.
```
//copy files: in.dat to out.dat check for
//successful file opening,
//use EOF to terminate copy loop
#include
#include
using namespace std;
int main()
{
ifstream in;
ofstream out;
in.open("in.dat");
if ( in.bad())
{
cout << "cannot open in.dat, aborting" << endl;
exit(1);
}
out.open("out.dat");
if (out.bad())
{
cout << "cannot open in.dat, aborting" << endl;
exit(1);
}
char ch;
while ( in.get(ch))
out << ch;
return 0;
}
```
You might also like to view...
What is the output of the following code fragment if the input values are 1 and 2?
``` int x; int y; cin >> x; cin >> y; cout << x << endl; cout << y << endl; ``` a. 1 2 b. 1 2 c. 12 d. xy
Attribute values do not allow you to control the format of the character data.
Answer the following statement true (T) or false (F)
Write the pseudocode for below problem
Given a temperature in the Fahrenheit scale, display its equivalent in the Celsius scale.
Which of the following commands lists file attributes?
a. ls b. ls -la c. ls -l d. ls -al