Q My friends use printf()in their C++ programs. Can I?
A No. At this point,printf()should properly be considered obsolete.
Workshop ............................................................................................................
The Workshop contains quiz questions to help solidify your understanding of the mater-
ial covered and exercises to provide you with experience in using what you’ve learned.
Try to answer the quiz and exercise questions before checking the answers in Appendix
D, and be certain you understand the answers before going to tomorrow’s lesson.
Quiz ................................................................................................................
- What is the insertion operator, and what does it do?
- What is the extraction operator, and what does it do?
- What are the three forms of cin.get(), and what are their differences?
- What is the difference between cin.read()and cin.getline()?
- What is the default width for outputting a longinteger using the insertion operator?
- What is the return value of the insertion operator?
- What parameter does the constructor to an ofstreamobject take?
- What does the ios::ateargument do?
Exercises ........................................................................................................
- Write a program that writes to the four standard iostream objects:cin,cout,cerr,
and clog. - Write a program that prompts the user to enter her full name and then displays it
on the screen. - Rewrite Listing 17.9 to do the same thing, but without using putback()or
ignore(). - Write a program that takes a filename as a parameter and opens the file for reading.
Read every character of the file and display only the letters and punctuation to the
screen. (Ignore all nonprinting characters.) Then close the file and exit. - Write a program that displays its command-line arguments in reverse order and
does not display the program name.
636 Day 17