std::basic_istream::sentry
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <istream> 中定义
|
||
template< class CharT, class Traits = std::char_traits<CharT>> class std::basic_istream<CharT, Traits>::sentry; |
||
An object of class basic_istream::sentry
is constructed in local scope at the beginning of each member function of std::basic_istream that performs input (both formatted and unformatted). Its constructor prepares the input stream: checks if the stream is already in a failed state, flushes the tie()'d output streams, skips leading whitespace if skipws flag is set, and performs other implementation-defined tasks if necessary. All cleanup, if necessary, is performed in the destructor, so that it is guaranteed to happen if exceptions are thrown during input.
目录 |
[编辑] 会员类型
traits_type
|
Traits |
[编辑] 成员函数
构建哨兵object. All的准备工作都在这里完成 原文: constructs the sentry object. All the preparation tasks are done here (公共成员函数) | |
finalizes the stream object after formatted input or after exception, if necessary (公共成员函数) | |
operator= [删除]</div></div>
|
无法复制转让 (公共成员函数) |
如果编写的流对象的检查是成功的 原文: checks if the preparation of the stream object was successful (公共成员函数) |
[编辑] 示例
#include <iostream> #include <sstream> struct Foo { char n[5]; }; std::istream& operator>>(std::istream& is, Foo& f) { std::istream::sentry s(is); if(s) is.read(f.n, 5); return is; } int main() { std::string input = " abcde"; std::istringstream stream(input); Foo f; stream >> f; std::cout.write(f.n, 5); std::cout << '\n'; }
输出:
abcde
[编辑] 另请参阅
提取物格式的数据 (公共成员函数) | |
提取字符和字符数组 原文: extracts characters and character arrays (函数模板) |