The rdstate() method of ios class in C++ is used to read the internal state of this stream.
Syntax:
CPP
CPP
iostate rdstate() const;Parameters: This method does not accept any parameter. Return Value: This method returns the current internal state of this stream. Example 1:
// C++ code to demonstrate
// the working of rdstate() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Stream
stringstream ss;
// Using rdstate() function
cout << "stream rdstate: "
<< ss.rdstate() << endl;
return 0;
}
Output:
Example 2:
stream rdstate: 0
// C++ code to demonstrate
// the working of rdstate() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Stream
stringstream ss;
ss.clear(ss.failbit);
// Using rdstate() function
cout << "stream rdstate: "
<< ss.rdstate() << endl;
return 0;
}
Output:
Reference: hhttps://cplusplus.com/reference/ios/ios/rdstate/stream rdstate: 4