Numration
#include <iostream>
#include <stdexcept>
using namespace std;
enum X { A, B, C };
istream& operator>> ( istream& in, X& x )
{
int val;
if ( in>> val ) {
switch ( val ) {
case A: case B: case C:
x = X(val); break;
default:
throw out_of_range ( "Invalid value for type X" );
}
}
return in;
}
int main()
{
X x;
try {
cin>> x;
cout<< x <<endl;
} catch ( out_of_range& ex ) {
cerr<< ex.what() <<endl;
}
}
Thoughtful Turtle