Chapter 1. Switching Streams
Difficulty: 2
What's the best way to dynamically use different stream sources and targets, including the standard console streams and files?
What are the types of
std::cin
andstd::cout
?Write an
ECHO
program that simply echoes its input and that can be invoked equivalently in the two following ways:ECHO <infile >outfile ECHO infile outfile
In most popular command-line environments, the first command assumes that the program takes input from
cin
and sends output tocout
. The second command tells the program to take its input from the file named infile and to produce output in the file named outfile. The program should be able to support all of the above input/output options.
Solution
1. What are the types of
std::cin
Get More Exceptional C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.