Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Member Functions get, put, fail, and eof Create a file called act 9B.txt and typ

ID: 3704628 • Letter: M

Question

Member Functions get, put, fail, and eof Create a file called act 9B.txt and type (or copy) the following text exactly as it (including the blank line between the two paragraphs) into that file 2. below into that file. You may cut and paste the following 10 blue lines appears We have learmed that "In" means go to a new line when it is used with the cout statement In C++, 'n' and "In" look very similar In fact, in a cout statement, they both act the same. However, they do not mean the same in all situations. 'n' is a value of type char and can be stored in a variable of type char, for example: int c On the other hand, "n"is a string that happens to be made up of one character. The following program reads the entire contents of the act9B.txt file and attempts to display its entire contents exactly as it appears above: /1 this program reads the entire contents of an input file and wili /I display it with the same format. #include

Explanation / Answer

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

void get_stream(ifstream& in_s,ofstream& out_s);

int main()
{
char c;
ifstream in_s; // declaration of the stream of type input
ofstream out_s; // declaration of the stream of type output
get_stream(in_s,out_s);
while(!in_s.eof()) // reading all characters one-bye-one to end // of file
{
in_s.get(c);
out_s.put(c);
}
in_s.close(); // close the file
out_s.close(); // close the file
return 0;
}
void get_stream(ifstream& in_s,ofstream& out_s)
{
char input_file[15];
cout<<"Enter the name of the input file: ";
cin>>input_file;

in_s.open(input_file); // connect to the input file and test
if(in_s.fail())
{
cout<<"Unable to open input file "<<input_file<<endl;
exit(EXIT_FAILURE);
}
out_s.open("out9B.txt");
return;
}