cin une c3 a9num c3 a9ration

Solutions on MaxInterview for cin une c3 a9num c3 a9ration by the best coders in the world

showing results for - "cin une c3 a9num c3 a9ration"
Danika
14 Jul 2019
1#include <iostream>
2#include <stdexcept>
3
4using namespace std;
5
6enum X { A, B, C };
7
8istream& operator>> ( istream& in, X& x )
9{
10  int val;
11
12  if ( in>> val ) {
13    switch ( val ) {
14    case A: case B: case C:
15      x = X(val); break;
16    default:
17      throw out_of_range ( "Invalid value for type X" );
18    }
19  }
20
21  return in;
22}
23
24int main()
25{
26  X x;
27
28  try {
29    cin>> x;
30    cout<< x <<endl;
31  } catch ( out_of_range& ex ) {
32    cerr<< ex.what() <<endl;
33  }
34}
similar questions
queries leading to this page
cin une c3 a9num c3 a9ration