3 ms·
My impression is that C++ streams are on their way out -- unlikely to be deprecated (too much existing code) but also unlikely to receive any more attention. T
by gumby 3y ago
My impression is that C++ streams are on their way out -- unlikely to be deprecated (too much existing code) but also unlikely to receive any more attention. They are old enough to likely not have any actual implementation bugs at this point, but in retrospect the design bugs from the 1980s are pretty serious.
The rapid incorporation of the excellent `format` package for printing points to a future falling back at least to ANSI buffered IO and possibly raw POSIX IO.
- synergy20 3y agoyou mean format + printf/scanf from C?
- signa11 3y agothis: https://en.cppreference.com/w/cpp/utility/format/format https://en.cppreference.com/w/cpp/utility/format/format most likely.
- corysama 3y agohttps://en.cppreference.com/w/cpp/header/format https://en.cppreference.com/w/cpp/header/format Which is based on https://fmt.dev/latest/index.html https://fmt.dev/latest/index.html
- gumby 3y agoAs others have pointed out I mean `std::format` et al in <format>. There's also a proposal for a type safe scanf: scnlib, sort of format in reverse: https://scnlib.dev/en/master/ https://scnlib.dev/en/master/
- jujube3 3y agoIs 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.
- jstimpfle 3y agoAFAIK the lifetime of the temporary is defined as being valid until the statement is done. So even printf("%s\n", obj.to_string().c_str()); should be perfectly fine.