Standard IO
Most command-line programs deal with input and output using either standard I/O or files. In this section, we explore both the C and C++ approaches to standard I/O. C Standard OutputC provides the Standard Output. Consider the following example double subTotal; double total; double salesTax; : printf( "Sales Report:\n" ); printf( "SubTotal: %8.2f\n", subTotal ); printf( "Sales Tax: %8.2f\n", salesTax ); printf( "Total Due: %8.2f\n", total ); There is no separate C function for printing a newline after the text is printed. To produce a newline, you must include the Format Specifiers.
The
The format-string consists of text and/or format specifiers. Any text within the string is printed verbatim, while format specifiers are replaced by values given as additional arguments.
All of the format specifiers have an optional integer width value following the printf( "%d %5d\n", value1, value2 ); printf( "%8f %6.3f %07.2f\n", avg1, avg2, avg3 ); The following table outlines the more common format specifiers that can be used with the
C Standard InputC++ Standard I/O
|