C++中的ios类的setstate()方法用于通过设置作为参数传递的标志来更改此流的当前状态。因此,此函数更改此流的内部状态。
用法:
void setstate(iostate state)
参数:此方法接受iostate作为参数,该参数是要在此流中设置的goodbit,failbit,eofbit和badbit标志的组合。
返回值:此方法不返回任何内容。
示例1:
// C++ code to demonstrate
// the working of setstate() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Stream 1
stringstream ss;
ss.clear(ss.goodbit);
// Stream 2
stringstream ss2;
cout << "current stream: " << ss2.rdstate() << endl;
// Using setstate() function
ss2.setstate(ss.rdstate());
// Print the result
cout << "updated stream: " << ss2.rdstate() << endl;
return 0;
}
输出:
current stream: 0 updated stream: 0
示例2:
// C++ code to demonstrate
// the working of setstate() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Stream 1
stringstream ss;
ss.clear(ss.failbit);
// Stream 2
stringstream ss2;
cout << "current stream: " << ss2.rdstate() << endl;
// Using setstate() function
ss2.setstate(ss.rdstate());
// Print the result
cout << "updated stream: " << ss2.rdstate() << endl;
return 0;
}
输出:
current stream: 0 updated stream: 4
参考: hhttp://www.cplusplus.com/reference/ios/ios/setstate/
相关用法
- C++ ios eof()用法及代码示例
- C++ ios bad()用法及代码示例
- C++ wcslen()用法及代码示例
- C++ norm()用法及代码示例
- C++ wcsspn()用法及代码示例
- C++ fill()用法及代码示例
- C++ wcscpy()用法及代码示例
- C++ wcscmp()用法及代码示例
- C++ conj()用法及代码示例
- C++ btowc()用法及代码示例
- C++ fill_n()用法及代码示例
- C++ ios clear()用法及代码示例
- C++ ios rdstate()用法及代码示例
- C++ quick_exit()用法及代码示例
注:本文由纯净天空筛选整理自guptayashgupta53大神的英文原创作品 ios setstate() function in C++ with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。