How to write a validation code for different types to input in C++ ?