Question's all in the title. I'm making a calculator and I obviously need input. I use the cin>> function but I was wondering if there is a way to test the input to find out if it's a number. If I enter anything that isn't a number the program crashes. Is there a built in function/operator? Please help!
- possible duplicate of How to convert a number to string and vice versa in C++KillianDS– KillianDS2012-07-29 09:22:45 +00:00Commented Jul 29, 2012 at 9:22
- 1@KillianDS it is not about "converting a number to string", but "checking if an input is a number"Rafi Kamal– Rafi Kamal2012-07-29 09:25:29 +00:00Commented Jul 29, 2012 at 9:25
- 1@rafl: you cannot check if it is a number without at least trying to convert. And most conversion functions offer a "fail" mechanism that you can use here. No need to reinvent the wheel at all.KillianDS– KillianDS2012-07-29 09:26:16 +00:00Commented Jul 29, 2012 at 9:26
- @KillianDS, sure, you can use a regex.edA-qa mort-ora-y– edA-qa mort-ora-y2012-07-29 11:12:30 +00:00Commented Jul 29, 2012 at 11:12
- @edA-qamort-ora-y and what does that regex actually do? It tries to interpret the string as a number, sounds much like conversion to me. It's not the method that you use for conversion that matters.KillianDS– KillianDS2012-07-29 11:46:43 +00:00Commented Jul 29, 2012 at 11:46
| Show 2 more comments