I was wondering if we can force std::cin so it doesn’t performs any implicit conversion between data types, for e.g:
unsigned int number;
cout<<"Please input a number :";
if(std::cin>>number)cout<<std::endl<<"Good number";
else cout<<"Bad number";
So if you punch -23 or 26.3 , it will simply perform implicit conversion and store the value in number which isn’t I want. So can we stop this?
Thanks
cinis going to store the value into the data type you provide.unsigned intwill not takesignednumbers so it will overflow to the largestunsigned intor to0. In your example, you are providing adoubleconstant, which is not anunsigned int. Change yourunsigned intto adoubleif you want it to work the way you intended.