A modern C++ library for type-safe and fast text parsing, replacing scanf and iostream.
scnlib is a modern C++ library that provides fast, type-safe text parsing to replace `scanf` and `std::istream`. It solves the problem of unsafe and slow input handling in C++ by offering an ergonomic interface with Python-like format strings and support for Unicode. As the reference implementation of the ISO C++ proposal P1729, it aims to modernize input parsing in the language.
C++ developers working on applications that require efficient and reliable text parsing, such as data processing tools, command-line interfaces, or systems where input performance is critical. It is especially useful for those transitioning from C-style `stdio` or iostreams to modern C++ practices.
Developers choose scnlib for its combination of type safety, high performance (benchmarked faster than iostream and scanf), and modern C++ features like ranges and compile-time format checking. Its alignment with upcoming C++ standards ensures future compatibility and reduces legacy code dependencies.
scanf for modern C++
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses variadic templates to ensure types are not determined by format strings, eliminating common scanf errors, and supports modern C++ features like ranges for flexible input handling.
Benchmarks show scn::scan outperforms std::stringstream and sscanf for integers, floats, and strings, with scn::scan_int being competitive with strtol while adding safety.
Returns values directly from scn::scan with no output parameters, improving code readability, and supports Python-like format strings with compile-time checking for reliability.
Requires and supports UTF-8, UTF-16, and UTF-32 input, and is tested across multiple platforms and architectures like x86, ARM, and RISC-V, ensuring broad compatibility.
Compilation takes around twice as long and uses significantly more memory compared to standard iostream, as shown in build time benchmarks, which can slow down development cycles.
In debug builds, executables using scnlib are approximately five times larger than those using scanf or iostream, even after stripping, which may impact debugging and deployment.
Relies on external libraries like fast_float and NanoRange, adding integration complexity and potential maintenance issues in projects that prefer minimal dependencies.