命名空间
变体
操作

标准库头文件 <iostream>

来自 cppreference.cn
< cpp‎ | header
 
 
标准库头文件
算法
<algorithm>
<numeric>
字符串
<cctype>
<cstring>
<cuchar> (C++11)
<cwchar>
<cwctype>
<string_view> (C++17)
<string>
文本处理
<clocale>
<codecvt> (C++11/17/26*)
<locale>
<regex> (C++11)
<text_encoding> (C++26)   
数值
<cfenv> (C++11)
<cmath>
<complex>
<linalg> (C++26)
<numbers> (C++20)
<random> (C++11)
<simd> (C++26)
<valarray>
时间
<chrono> (C++11)
<ctime>
C 兼容性
<ccomplex> (C++11/17/20*)
<ciso646> (until C++20)
<cstdalign> (C++11/17/20*)
<cstdbool> (C++11/17/20*)
<ctgmath> (C++11/17/20*)
 

此头文件是 输入/输出 库的一部分。

包含 <iostream> 的行为就像它定义了一个类型为 std::ios_base::Init 的静态存储期对象,如果它是第一个被构造的 std::ios_base::Init 对象,则其构造函数初始化标准流对象,并且如果它是最后一个被销毁的 std::ios_base::Init 对象,则其析构函数刷新这些对象(cinwcin 除外)。

内容

包括

(C++11)
std::ios_base 类,std::basic_ios 类模板和 typedefs[编辑]
std::basic_streambuf 类模板[编辑]
(C++11)
std::basic_istream 类模板和 typedefs[编辑]
(C++11)
std::basic_ostream, std::basic_iostream 类模板和 typedefs[编辑]

对象

从标准 C 输入流 stdin 读取
(全局对象)[编辑]
写入标准 C 输出流 stdout
(全局对象)[编辑]
写入标准 C 错误流 stderr,无缓冲
(全局对象)[编辑]
写入标准 C 错误流 stderr
(全局对象)[编辑]

[编辑] 概要

#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
 
namespace std {
  extern istream cin;
  extern ostream cout;
  extern ostream cerr;
  extern ostream clog;
 
  extern wistream wcin;
  extern wostream wcout;
  extern wostream wcerr;
  extern wostream wclog;
}

[编辑] 缺陷报告

以下行为变更的缺陷报告被追溯应用于先前发布的 C++ 标准。

DR 应用于 已发布行为 正确行为
LWG 155 C++98 静态对象的类型是 std::basic_ios::Init
(不严格错误,但措辞具有误导性)
更正为 std::ios_base::Init
LWG 1123 C++98 包含 <iostream> 不保证
std::ios_base::Init 对象的构造
保证