[ create a new paste ] login | about

Link: http://codepad.org/OItN2kVz    [ raw code | output | fork ]

C++, pasted on Dec 4:
#include <iostream>

int main( void )
{
	using namespace std ;
	
	cin.exceptions( ios::badbit | ios::eofbit | ios::failbit ) ;
	
	while( true )
	{
		try
		{
			char c ;
			
			c = cin.get() ;
				
			cout << c ;
		}
		
		catch( ios::failure & e )
		{
			if( cin.bad() )
			{
				cout << "bad" << endl ;
			}
			
			if( cin.eof() )
			{
				cout << "eof" << endl ;
			}
			
			if( cin.fail() )
			{
				cout << "fail" << endl;
			}
			
			break ;
		}		
	}

	return 0 ;
}


Output:
1
2
eof
fail


Create a new paste based on this one


Comments: