diff --git a/README.md b/README.md index 16dee53..e12fc10 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Example: ```C++ #include "fast_float/fast_float.h" #include +#include int main() { std::string input = "3.1416 xyz "; @@ -68,6 +69,25 @@ int main() { } ``` +Though the C++17 standard has you do a comparison with `std::errc()` to check whether the conversion worked, you can avoid it by casting the result to a `bool` like so: + +```cpp +#include "fast_float/fast_float.h" +#include +#include + +int main() { + std::string input = "3.1416 xyz "; + double result; + if(auto answer = fast_float::from_chars(input.data(), input.data() + input.size(), result)) { + std::cout << "parsed the number " << result << std::endl; + return EXIT_SUCCESS; + } + std::cerr << "failed to parse " << result << std::endl; + return EXIT_FAILURE; +} +``` + You can parse delimited numbers: ```C++