Skip to content
Related Articles

Related Articles

Improve Article

ios rdstate() function in C++ with Examples

  • Last Updated : 02 Sep, 2019

The rdstate() method of ios class in C++ is used to read the internal state of this stream.

Syntax:

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:
stream rdstate: 0

Example 2:




// 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:
stream rdstate: 4

Reference: hhttp://www.cplusplus.com/reference/ios/ios/rdstate/

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.



My Personal Notes arrow_drop_up
Recommended Articles
Page :