4 ms·
Is there any reason to use the format package rather than printf? Aside from C++ people who claim to hate C needing to save face?
by jujube3 3y ago
Is there any reason to use the format package rather than printf? Aside from C++ people who claim to hate C needing to save face?
- IcyWindows 3y agoThe library overview goes over the reasons fairly succinctly: https://fmt.dev/latest/index.html#overview https://fmt.dev/latest/index.html#overview
- pjmlp 3y agoOther than caring about type safety, and possible CVEs due to misuse of format strings?
- flohofwoe 3y agoI like C much more than C++, but even with that must say that https://github.com/fmtlib/fmt https://github.com/fmtlib/fmt is pretty nice (which is the base for std::format). Together with pystring (https://github.com/imageworks/pystring https://github.com/imageworks/pystring) it makes string processing in C++ somewhat bearable (pystring is slow though because it still uses the std::string type which excessively allocates, but at least it's convenient compared to 'raw' C++ string functionality).
- amelius 3y agoThe problem with printf and C++ is that you can't do this in general: printf("%d %s", i, obj.convert_to_string()) because the const char* you get from obj.convert_to_string() might be deleted from the heap before printf() is called. And similar issues.