如何确定std::strtof是成功还是失败?

How to be sure whether std::strtof succeeded or failed?

如果strtof无法转换字符串,则returns0.0。 http://www.cplusplus.com/reference/cstdlib/strtof/ 没有说明函数对 endptr 做了什么以防转换不成功(在这种情况下行为是否未定义?)

如何区分解析为 0 的字符串的成功转换和失败的转换?

来自 cppreference float strtof(const char* str, char** str_end):

If no conversion can be performed, ​0​ is returned and *str_end is set to str.

因此您可以检查是否 *str_end == str,因为在任何其他情况下(例如读取文字 0)*str_end 必须至少提前一个字符。