Services
Discover
Homeschooling
Ask a Question
Log in
Sign up
Filters
Done
Question type:
Essay
Multiple Choice
Short Answer
True False
Matching
Topic
Computing
Study Set
Absolute C++
Quiz 12: Streams and File IO
Path 4
Access For Free
Share
All types
Filters
Study Flashcards
Practice Exam
Learn
Question 21
Essay
What output will be produced when the following code is executed? (Assume these lines are embedded in complete,correct programs,with proper #include directives. ) cout << "*"; cout.width(5); cout << 123 << "*" << 123 << "*" << endl; cout << setw(5)<< 123 << "*" << 123 << "*" << endl;
Question 22
Essay
Assume you have opened and connected stream variables fileIn and fileOut.Assume further that you have finished with the input and output files.Write the statements necessary to close these files.
Question 23
Essay
Given the following code.The input file,in.dat,is a copy of the program code in this problem.How will the output file,out.dat,differ from the input file? // file: testQuestion.cc // test question: copy files: in.dat to out.dat // in.dat is a copy of a file containing this code. // use EOF to terminate copy loop #include <fstream> #include <cstdlib> // for exit() using namespace std; int main() { ifstream in; ofstream out; in.open("in.dat"); out.open("out.dat"); while(in >> ch) out << ch; return 0; }
Question 24
Essay
Assume you have opened and connected stream variables fileIn and fileOut.Assume further that you have finished with input file,but want to read the input file a second time.What is necessary to set the stream state to reread the file from the start? Explain.
Question 25
Essay
You have a file that is not empty.You open a file stream for write,and attach the stream to the file.Then you close the file.What is now in that file?
Question 26
Essay
What output is produced by the following code,assuming these lines of code are embedded in a correct program? cout << "*" << setw(5)<< 123 << "*" << 123 << "*" << endl; cout.setf(ios::showpos); cout << "*" << setw(5)<< 123 << "*" << 123 << "*" << endl; cout.unsetf(ios::showpos): cout.setf(ios::left); cout << "*" << setw(5)<< 123 << "*" << setw(5)<< 123 << "*" << endl;
Question 27
Essay
You are writing a program.Give the necessary statements to open a file and to confirm that the file has been successfully opened for writing.Important: Why bother to test?
Question 28
Essay
You have a file that is not empty,and you want to preserve the contents and append to the end of the file.Give the commands necessary to open a file for appending.
Question 29
Essay
Write a loop that will read from the current position in a file up to the end of the current line,and send this output to the screen.You may assume that any variables you need are declared,including file variables,and that any needed files have been successfully opened.
Question 30
Essay
Write a program that prompts for an input file name,receives the input file name in a C-string.The program should check for errors opening a file.It is not necessary for the program to do anything other than open the file.
Question 31
Essay
What is sent to screen when the following is executed,assuming that these lines of code are embedded in a correct,complete program? Explain this behavior. cout << "*" << setw(3)<< 123456 << "*" << endl;
Question 32
Essay
What will be the output from this code fragment if embedded in an otherwise correct and complete C++ program that is supplied the following input? Input: 12 23 45 Code: ifstream inStream("File.txt"); int i = 0,next; while (cin >> next) {
\quad
i++;
\quad
cout << next << end; } inStream.close(); cout << count << flush;
Question 33
Essay
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.
Question 34
Essay
What happens to output when data is sent to the output stream width that is wider than that set with the setw(int)manipulator,or equivalently,with cout.width(int)?
Question 35
Essay
Declare and open input file stream fileIn and output file stream fileOut.Attach these to files named input.dat and output.dat.Write #include directives for any required header files.Make certain names from namespaces are accessible.