I/O manipulators | ||||
Print functions(C++23) | ||||
C-style I/O | ||||
Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
Types and objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Defined in header <cstdio> | ||
#define stdin /* implementation-defined */ | (1) | |
#define stdout /* implementation-defined */ | (2) | |
#define stderr /* implementation-defined */ | (3) | |
Three text streams are predefined. These streams are implicitly opened and unoriented at program startup.
What constitutes an interactive device is implementation-defined.
These macros are expanded to expressions of typestd::FILE*.
Although not mandated by POSIX, the UNIX convention is thatstdin
andstdout
are line-buffered if associated with a terminal andstderr
is unbuffered.
These macros may be expanded to modifiable lvalues. If any of thesestd::FILE* lvalue is modified, subsequent operations on the corresponding stream result in unspecified or undefined behavior.
This example shows a function similar tostd::printf.
#include <concepts>#include <cstdio>#include <type_traits> template<typename T>concept IsPrintable=std::integral<T> orstd::floating_point<T> orstd::is_pointer_v<T>; int my_printf(charconst*const format, IsPrintableautoconst ...arguments){returnstd::fprintf(stdout, format, arguments...);} int main(int argv,char*[]){ my_printf("Strings and chars:\t%s %c\n","hello",'x'); my_printf("Rounding:\t\t%f %.0f %.32f\n",1.5,1.5,1.3); my_printf("Padding:\t\t%05.2f %.2f %5.2f\n",1.5,1.5,1.5); my_printf("Scientific:\t\t%E %e\n",1.5,1.5); my_printf("Hexadecimal:\t\t%a %A 0x%X\n",1.5,1.5,&argv);}
Possible output:
Strings and chars: hello xRounding: 1.500000 2 1.30000000000000004440892098500626Padding: 01.50 1.50 1.50Scientific: 1.500000E+00 1.500000e+00Hexadecimal: 0x1.8p+0 0X1.8P+0 0x2CFB41BC
reads from the standard C input streamstdin (global object)[edit] | |
writes to the standard C output streamstdout (global object)[edit] | |
writes to the standard C error streamstderr, unbuffered (global object)[edit] | |
writes to the standard C error streamstderr (global object)[edit] | |
(C++11) | prints formatted output tostdout, a file stream or a buffer (function)[edit] |
object type, capable of holding all information needed to control a C I/O stream (typedef)[edit] | |
C documentation forstdin,stdout,stderr |