Here Im trying to get an integer from user, looping while the input is correct.
After entering non integer value (e.g \"dsdfgsdg\") cin.fail() returns true, as expec
cin.clear() does not clear the buffer; it resets the error flags. So you will still have the sting you entered in your buffer and the code will not allow you to enter new data until you clear the cin buffer. cin.Ignore() should do the trick
cin.Ignore()