Created
July 17, 2015 11:19
-
-
Save krysseltillada/4e22a74d923e7df36a74 to your computer and use it in GitHub Desktop.
function that takes and detects conditions of stream
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> /// std::istream; std::cout; std::endl; | |
std::istream &states (std::istream &is,const int &i) { | |
is >> const_cast<int&>(i); | |
if (is.rdstate () == std::cin.eofbit) | |
std::cout << "reached end of file " << std::endl; | |
else if (is.rdstate () == std::cin.badbit) | |
std::cout << "bad bit " << std::endl; | |
else if (is.rdstate () == std::cin.failbit) { | |
std::cout << "fail bit " << std::endl; | |
} | |
else if (is.rdstate () == std::cin.goodbit) | |
std::cout << "good bit " << std::endl; | |
return is; | |
} | |
int main () | |
{ | |
auto return_state = states(std::cin, 1).rdstate(); | |
if (return_state == std::cin.goodbit) | |
std::cout << "return goodbit " << std::endl; | |
else | |
std::cout << "return badbit " << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment