- Where Developers Learn, Share, & Build Careers


I am working on a project where I input the form {float} {single-letter-identifier} , for example 15.6E , or 10W .

To do this, I thought I could take the input string, strip it from the last letter and then check to see if using std :: stof Can be converted to float. It will be nested in the try-catch block, and I will be allowed to inform the user of invalid input.

The STL Open-Standard (page 653) states that std :: stof throws:

invalid_argument If wcstod or wcstold reports that no conversions can be done.

However, when it can not be changed, nothing is passed, for example "48East" . To recreate this behavior, a code sample is below:

  std :: wstring szString = L "48East"; Try {float f = std :: stof (szString); } Hold (...) {std :: cout & lt; & Lt; "Exam" & lt; & Lt; Std :: endl; }   

It has been compiled on MSWC10 in debug mode with / ode , so I'm assuming that the call has not been optimized.

I appreciate any help (or guidance where I have misunderstood / can forget the imagination!).

As I read it, stof as more input string Converts it, until it changes nothing it can not change if it can not change anything to invalid_argument .

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -