I consider using the C++17's
std::from_chars_result from_chars(const char* first, const char* last, ...);
due to its nice error codes (including range checking, whereas strtof etc. need to call GetLastError ).
I typically have three variants for converting a C string:
convert the C string [first, implicit last)
convert the C string [first, last)
convert the C string [first, implicit last) prefix
So for example, "10K" will be converted to an integer 10 in the last case.
Is it somehow possible to do this as well with from_chars?
↧