C++:iostream 的使用

std::iostream


Input/output stream

  • ios_base
  • ios
  • istream
  • ostream
  • iostream
  • fstream
  • stringstream

[NOTE: 这里是 iostream 类,若想了解 iostream 库,请看 Input/Output library.]

该类内部所有成员继承自 istream类和 ostream类,因此能进行输入和输出的操作。

该类依赖于单一 streambuf 对象进行输入输出操作。

该类保存一个继承自ios_base, ios and istream的内部字段集合。


公共成员函数继承自 istream

(public member function )

operator>>

提取格式化输入

gcount

获取字符串长度,统计char字符数量

get

从流中提取字符,作为未格式化的输入

getline

从流中提取字符直到遇到分隔字符

ignore

提取特定字符并丢弃

peek

提取下一个字符,并放回

read

提取若干个字符并存入数组

readsome

从缓冲区提取若干个字符并存入数组

putback

Put character back (public member function )

unget

Unget character (public member function )

tellg

返回输入流中当前字符的位置

seekg

设置要从输入流中提取的下一个字符的位置

sync

从标准输入的字符buffer中删除任何未读的字符


公共成员函数继承自 ostream

(public member function )

operator<<

插入格式化输出

put

将字符c插入流中

write

将s指向的数组的前n个字符插入到流中

tellp

获取要将下一个字符插入输出流的位置

seekp

设置要将下一个字符插入输出流的位置

flush

刷新输出流缓冲区


公共成员函数继承自 ios

(public member function )

good

检查 stream 的状态是否正常

eof

检查是否设置了eofbit,即是否正常读到文件结尾

fail

检查是否设置了failbit或badbit,即非正常结束

bad

检查是否设置了badbit,即非正常结束

operator!

评估流打开状态,如果返回为true即设置了failbit或badbit

operator bool (C++11)

评估流打开状态,如果返回为true即设置了goodbit

rdstate

获取错误状态flags

setstate

设置错误状态flag

clear

清除flags

copyfmt

复制对应格式信息

fill

获取/设置填充字符

exceptions

Get/set exceptions mask (public member function )

imbue

Imbue locale (public member function )

tie

Get/set tied stream (public member function )

rdbuf

Get/set stream buffer (public member function )

narrow

Narrow character (public member function )

widen

Widen character (public member function )


公共成员函数继承自 ios_base

(public member function )

flags

获取/设置格式标志

setf

设置特定格式标志

unsetf

清除特定格式标志

precision

获取/设置浮点小数精度

width

获取/设置字段宽度

imbue

Imbue locale (public member function )

getloc

Get current locale (public member function )

xalloc

Get new index for extensible array [static] (public static member function )

iword

Get integer element of extensible array (public member function )

pword

Get pointer element of extensible array (public member function )

register_callback

Register event callback function (public member function )

sync_with_stdio

Toggle synchronization with cstdio streams [static] (public static member function )


 

你可能感兴趣的:(C++)