Horje
cin une énumération Code Example
cin une énumération
#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;
  }
}




Cpp

Related
faxc Code Example faxc Code Example
Chef and IPC Certificates codechef solution in c++ Code Example Chef and IPC Certificates codechef solution in c++ Code Example
how to create more than one vector in vector cpp Code Example how to create more than one vector in vector cpp Code Example
comment installer boost c++ sur windows Code Example comment installer boost c++ sur windows Code Example
set keybinding for compiling c++ program in neovim Code Example set keybinding for compiling c++ program in neovim Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7