If the input cannot be converted to double, then failbit will be set to cin . This can be verified by calling cin.fail() .
cin>>a>>b; if(cin.fail()) { cout<<"data entered is not of double type"; }
Update. As others have pointed out, you can use !cin cin.fail() instead of cin.fail() . These are two equivalents.
source share