Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Printf
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===2020s: std::print === To address usability issues with the existing [[C++]] [[input/output (C++)|input/output support]], as well as avoid safety issues of printf<ref>{{cite web|url=https://hownot2code.wordpress.com/2016/08/10/beware-of-printf|title=How Not to Code: Beware of printf|date=10 August 2016 }}</ref> the [[C++ standard library]] was revised<ref>{{cite web|url=https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2216r2.html|title=C++20 Format improvements proposal to enable compile-time checks}}</ref> to support a new type-safe formatting starting with [[C++20]].<ref>{{cite web|url=https://en.cppreference.com/w/cpp/utility/format/format|title=C++20 std::format}}</ref> The approach of {{code|std::format|cpp}} resulted from incorporating Victor Zverovich's {{code|libfmt}}<ref>{{cite web|url=https://fmt.dev|title=libfmt: a modern formatting library}}</ref> API into the language specification<ref>{{cite web|url=https://www.accu.org/journals/overload/29/166/collyer/|title=C++20 Text Formatting: An Introduction}}</ref> (Zverovich wrote<ref>{{cite web|url=https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0645r10.html|title=C++ Format Proposal History}}</ref> the first draft of the new format proposal); consequently, {{code|libfmt}} is an implementation of the C++20 format specification. In [[C++23]], another function, {{code|std::print|cpp}}, was introduced that combines formatting and outputting and therefore is a functional replacement for {{code|printf()}}.<ref>{{cite web|url=https://en.cppreference.com/w/cpp/io/print|title=C++ print}}</ref> As the format specification has become a part of the language syntax, a C++ compiler is able to prevent invalid combinations of types and format specifiers in many cases. Unlike the {{kbd|-Wformat}} option, this is not an optional feature. The format specification of {{code|libfmt}} and {{code|std::format|cpp}} is, in itself, an extensible "mini-language" (referred to as such in the specification),<ref>{{cite web|url=https://fmt.dev/6.2.1/syntax.html#format-specification-mini-language|title=Format Specification Mini-Language}}</ref> an example of a [[domain-specific language]]. As such, {{code|std::print|cpp}}, completes a historical cycle; bringing the state-of-the-art (as of 2024) back to what it was in the case of Fortran's first {{code|PRINT|fortran}} implementation in the 1950s<!--overly colorful and debatable-->.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)