/* testfmt01.cpp CIS 150 7/1/2008 David Klick Demonstration of printf. */ #include #include using std::cin; using std::cout; void cont(); int main() { int n = 1234567; double x = 1234.5678; char c = 'W'; char* msg = "Hello, world!"; printf("printf formatting demonstration\n\n"); printf("n = %d\nx = %f\n", n, x); printf("12345678901234567890\n"); printf("%10d\n", n); printf("%010d\n", n); printf("%-10d\n", n); printf("%+10d\n", n); printf("%5d\n", n); printf("%X\n", n); printf("%o\n", n); printf("%12.3f\n", x); printf("%.2f\n", x); printf("The char value is '%c'\nMy message is: %s\n", c, msg); printf("%s\n", msg); printf("%.9s\n", msg); cont(); return 0; } /* void cont(); Arguments: none Returns: nothing Clears input buffer and pauses waiting for user to press Enter. */ void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); } /* Sample output: printf formatting demonstration n = 1234567 x = 1234.567800 12345678901234567890 1234567 0001234567 1234567 +1234567 1234567 12D687 4553207 1234.568 1234.57 The char value is 'W' My message is: Hello, world! Hello, world! Hello, wo */