???C++?printf
??????????,???????????????????????????????:
- ??????:??
printf
???????????????,??????????????????:
#includeint main() { int a = 42; float b = 3.14f; char c = 'A'; const char* s = "Hello, World!"; printf("Integer: %d\n", a); printf("Float: %.2f\n", b); printf("Character: %c\n", c); printf("String: %s\n", s); return 0; }
- ?????:??
printf
??????,???????????????:
#includeint main() { int a = 42; float b = 3.14f; printf("Width: ]\n", a); printf("Precision: %.2f\n", b); printf("Fill character: d\n", a); return 0; }
- ??????:??
printf
???????????,?????????????????:
#include#include int main() { int min_int = std::numeric_limits ::min(); int max_int = std::numeric_limits ::max(); const char* null_ptr = nullptr; printf("Minimum int: %d\n", min_int); printf("Maximum int: %d\n", max_int); printf("Null pointer: %s\n", (null_ptr ? null_ptr : "NULL")); return 0; }
- ??????:??
printf
???????????,?????????????:
#includeint main() { int a = 42; printf("Invalid format specifier: %x\n", a); // ???? %d ? %i return 0; }
-
????:??
printf
??????????????,????????????????????????? -
?????:???????????,????
printf
?????????????,?????????,???????printf
????,?????????????? -
?????????:????????????,????
printf
??????????????,?????printf
???????????????????
?????????????,?????printf
???????????????????,????????????????????