Chapter 6: Problem 21
(This exercise is for those who have studied the optional section entitled
"File Names as Input." ) Suppose you are given the following string variable
declaration and input statement.
#include
Chapter 6: Problem 21
(This exercise is for those who have studied the optional section entitled
"File Names as Input." ) Suppose you are given the following string variable
declaration and input statement.
#include
All the tools & learning materials you need for study success - in one app.
Get started for freeSuppose c is a variable of type char. What is the difference between the following two statements? cin >> c; and cin.get(c);
Write the definition for a void function called text_to_screen that has one formal parameter called \(f\) ile_stream that is of type ifstream. The precondition and postcondition for the function are as follows: //Precondition: The stream file_stream has been connected //to a file with a call to the member function open. //Postcondition: The contents of the file connected to //file_stream have been copied to the screen character by //character, so that the screen output is the same as the //contents of the text in the file. //(This function does not close the file.)
Consider the following code (and assume that it is embedded in a com- plete and correct program and then run): char next; int count = 0; cout << "Enter a line of input:\n"; cin.get(next); while (next != '\n') { if ((count%2) == 0) cout << next; count++; cin.get(next); } If the dialogue begins as follows, what will be the next line of output? Enter a line of input: abcdef gh
What output will be sent to the file stuff.dat when the following lines are executed (assuming the lines are embedded in a complete and correct program with the proper include directives)? ofstream fout; fout.open("stuff.dat"); fout << "*" << setw(5) << 123 << "*" << 123 << "*" << endl; fout.setf(ios::showpos); fout << "*" << setw(5) << 123 << "*" << 123 << "*" << endl; fout.unsetf(ios::showpos); fout.setf(ios::left); fout << "*" << setw(5) << 123 << "*" << setw(5) << 123 << "*" << endl;
(This question is for those who have read the optional section "The putback Member Function." ) The putback member function "puts back" a symbol into an input stream. Does the symbol that is put back have to be the last symbol input from the stream? For example, if your program reads an 'a' from the input stream, can it use the putback function to put back a 'b', or can it only put back an 'a'?
What do you think about this solution?
We value your feedback to improve our textbook solutions.