Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
  }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: passing array to the function c++ 
Cpp :: Write a CPP program to calculate sum of first N natural numbers 
Cpp :: c++ system() from variable 
Cpp :: how initilaize deffult value to c++ class 
Cpp :: preorder to postorder converter online 
Cpp :: c++ arrays 
Cpp :: std::ifstream cant read file to large 
Cpp :: Use of Scope Resolution operator for namespace 
Cpp :: atomic int c++ add 1 
Cpp :: set(W) 
Cpp :: how to find the sum of elements in a stack in cpp 
Cpp :: MPI_PUT 
Cpp :: determining a string is subsequence of another 
Cpp :: add two constant char pointers c++ 
Cpp :: export gcc g++ 
Cpp :: c++ konsolenausgabe 
Cpp :: c++ program to convert kelvin to celsius 
Cpp :: No Index Out of Bound Checking in C++ 
Cpp :: c++ program 
Cpp :: c++ ignore_line 
Cpp :: sort n characters in descending order c++ 
Cpp :: C++ if...else Statement 
Cpp :: librerias matematicas en c++ para numeros aleatorios 
Cpp :: show mouse c++ 
Cpp :: pca compact trick 
Cpp :: C++ Things to Remember 
Cpp :: c++ arreglo/array 
Cpp :: how to analyse a poem 
Cpp :: c++ multi-dimensional arrays 
Cpp :: program to find third smallest number c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =