I am new to C++. I wrote a function in which I want the user to enter an integer value. I know how to prevent the input of characters using:
if(!(cin>>a)) or
if (cin.fail()) where a is of type int. If the user enters characters first and then numbers for eg: ab12 the code works, but if the user inputs the other way round, e.g 12ab, 12 is taken as the input value. How can I prevent that?