C++ 头文件系列(ostream)

1. 简介

头文件ostream主要定义了一个输出流类模版basic_ostream,该模版继承自basic_ios模版。

2. basic_ostream模版

2.1 sentry类

与basic_istream模版一样,basic_ostream也定义了一个sentry类,详见basic_istream::sentry

2.2 流定位函数

  • seekp : 定位到指定位置。
  • tellp : 返回当前位置。

2.3 格式化输出函数

  • operator <<(成员函数) : 输出变量,包括bool、short等(不包括char有关类型)。
  • operator <<(全局模版函数) : 输出char相关类型对象,包括char、unsigned char等。

2.4 非格式化输出函数

  • put : 输出一个字符。
  • write : 输出一块字符。

2.5 同步函数

  • flush : 刷新输出流缓冲区(实际上调用pubsync函数, 为同步语义)。

3 manipulators

  • endl : 输出换行符(‘ ’),并刷新缓冲区。
  • ends : 输出空字符。
  • flush : 刷新缓冲区。

4 typedefs

  • typedef basic_ostream<char> ostream;
  • typedef basic_ostream<wchar_t> wostream;
原文地址:https://www.cnblogs.com/lgxZJ/p/6408417.html