stdin, stdout, stderr
| 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<cstdio>
|
||
|
#define stdin /* implementation-defined */
|
(1) | |
|
#define stdout /* implementation-defined */
|
(2) | |
|
#define stderr /* implementation-defined */
|
(3) | |
预定义了三个文本流。这些流在程序启动时隐式打开且无方向性。
交互式设备的构成由实现定义。
这些宏展开为类型 std:: FILE * 的表达式。
注释
尽管POSIX未作强制要求,但UNIX惯例规定:若
stdin
和
stdout
关联到终端设备则采用行缓冲模式,而
stderr
始终采用无缓冲模式。
这些宏可能展开为可修改的左值。如果这些 std:: FILE * 左值中的任何一个被修改,后续对相应流的操作将导致未指定或未定义行为。
示例
此示例展示了一个类似于 std::printf 的函数。
#include <concepts> #include <cstdio> #include <type_traits> template<typename T> concept IsPrintable = std::integral<T> or std::floating_point<T> or std::is_pointer_v<T>; int my_printf(char const* const format, IsPrintable auto const ... arguments) { return std::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); }
可能的输出:
Strings and chars: hello x Rounding: 1.500000 2 1.30000000000000004440892098500626 Padding: 01.50 1.50 1.50 Scientific: 1.500000E+00 1.500000e+00 Hexadecimal: 0x1.8p+0 0X1.8P+0 0x2CFB41BC
参见
|
从标准C输入流
stdin
读取
(全局对象) |
|
|
写入到标准C输出流
stdout
(全局对象) |
|
|
写入到标准C错误流
stderr
,无缓冲
(全局对象) |
|
|
写入到标准C错误流
stderr
(全局对象) |
|
|
(C++11)
|
将格式化输出打印到
stdout
、文件流或缓冲区
(函数) |
|
对象类型,能够保存控制C I/O流所需的所有信息
(类型定义) |
|
|
C 文档
关于
stdin
,
stdout
,
stderr
|
|