“cpp/io/basic ios/setstate”的版本间的差异
来自cppreference.com
小 |
|||
第1行: | 第1行: | ||
− | {{cpp/io/basic_ios/title | setstate}} | + | {{cpp/io/basic_ios/title|setstate}} |
{{cpp/io/basic_ios/navbar}} | {{cpp/io/basic_ios/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
− | {{dcl | | + | {{dcl| |
void setstate( iostate state ); | void setstate( iostate state ); | ||
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
− | 在当前已设置表之外,设置流错误状态标志 {{ | + | 在当前已设置表之外,设置流错误状态标志 {{|state}}。实质上调用 {{c|clear(rdstate() {{!}} state)}}。可能抛出异常。 |
===参数=== | ===参数=== | ||
{{par begin}} | {{par begin}} | ||
− | {{par | state |要设置的流错误状态标志。 | + | {{par | state |要设置的流错误状态标志。 为下列常量的组合: |
{{cpp/io/ios_base/iostate consts}} | {{cpp/io/ios_base/iostate consts}} | ||
}} | }} | ||
第21行: | 第21行: | ||
===示例=== | ===示例=== | ||
{{example | {{example | ||
− | + | |code= | |
− | + | ||
#include <iostream> | #include <iostream> | ||
#include <sstream> | #include <sstream> | ||
第30行: | 第29行: | ||
std::ostringstream stream; | std::ostringstream stream; | ||
− | if (!stream.fail()) | + | if (!stream.fail()) |
std::cout << "stream is not fail\n"; | std::cout << "stream is not fail\n"; | ||
− | |||
stream.setstate(std::ios_base::failbit); | stream.setstate(std::ios_base::failbit); | ||
− | if (stream.fail()) | + | if (stream.fail()) |
std::cout << "now stream is fail\n"; | std::cout << "now stream is fail\n"; | ||
− | |||
− | if (!stream.good()) | + | if (!stream.good()) |
std::cout << "and stream is not good\n"; | std::cout << "and stream is not good\n"; | ||
− | |||
} | } | ||
− | + | |output= | |
stream is not fail | stream is not fail | ||
now stream is fail | now stream is fail | ||
第52行: | 第48行: | ||
===参阅=== | ===参阅=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/io/basic_ios/dsc rdstate}} | + | {{dsc inc|cpp/io/basic_ios/dsc rdstate}} |
− | {{dsc inc | cpp/io/basic_ios/dsc clear}} | + | {{dsc inc|cpp/io/basic_ios/dsc clear}} |
{{dsc end}} | {{dsc end}} | ||
{{langlinks|de|en|es|fr|it|ja|pt|ru}} | {{langlinks|de|en|es|fr|it|ja|pt|ru}} |
2023年12月13日 (三) 11:07的最后版本
void setstate( iostate state ); |
||
在当前已设置表之外,设置流错误状态标志 state。实质上调用 clear(rdstate() | state)。可能抛出异常。
目录 |
[编辑] 参数
state | - | 要设置的流错误状态标志。可为下列常量的组合:
|
[编辑] 返回值
(无)
[编辑] 示例
运行此代码
#include <iostream> #include <sstream> int main() { std::ostringstream stream; if (!stream.fail()) std::cout << "stream is not fail\n"; stream.setstate(std::ios_base::failbit); if (stream.fail()) std::cout << "now stream is fail\n"; if (!stream.good()) std::cout << "and stream is not good\n"; }
输出:
stream is not fail now stream is fail and stream is not good
[编辑] 参阅
返回状态标志 (公开成员函数) | |
修改状态标志 (公开成员函数) |