C++ Primer For Java Programmers Input And Output<< | Table of Contents | >>
C Standard Input/OutputC provides the Standard Output. Consider the following example (:source lang=cpp:)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. (:note warn:)
No error checking is performed by the 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
Standard Input. C File Input/OutputC++ Standard Input/OutputC++ File Input/Output
|