Why does std::stof not throw when passed an argument it cannot convert?
问题 I'm working on a project where I want to accept an input of the form {float}{single-letter-identifier} , for example 15.6E , or 10W . To do this, I thought that I could take the input string, strip off the last letter and then check to see if a conversion could be performed to float, using std::stof . This would be nested in a try-catch block, and allow me to notify the user of invalid input. The open-standard of the STL here (page 653) states that std::stof throws: invalid_argument if wcstod