A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../utility/format.html below:

Formatting library (since C++20) - cppreference.com

The text formatting library offers a safe and extensible alternative to the printf family of functions. It is intended to complement the existing C++ I/O streams library.

[edit] Format specifications

Format specification specifies how objects are formatted with different kinds of options.

The formatting of objects of basic types and standard string types uses the basic format specification. Other library components may also provide their own format specifications, see here for details.

[edit] Formatting functions stores formatted representation of the arguments in a new string
(function template) [edit] writes out formatted representation of its arguments through an output iterator
(function template) [edit] writes out formatted representation of its arguments through an output iterator, not exceeding specified size
(function template) [edit] determines the number of characters necessary to store the formatted representation of its arguments
(function template) [edit] [edit] Format strings [edit] Formatting concepts specifies that a type is formattable, that is, it specializes std::formatter and provides member functions parse and format
(concept) [edit] [edit] Extensibility support and implementation detail [edit] Helper items (since C++23) [edit] Notes

We intentionally treat the addition of std::basic_format_string (P2508) as a defect report because all known implementations make these components available in C++20 mode, although it is not so categorized officially.

[edit] Example
#include <cassert>
#include <format>
 
int main()
{
    std::string message = std::format("The answer is {}.", 42);
    assert(message == "The answer is 42.");
}
[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior P2418R2 C++20 objects that are neither const-formattable nor copyable
(such as generator-like objects) are not formattable allow formatting these objects
(relaxed formatter requirements) P2508R1 C++20 there's no user-visible name for this facility the name basic_format_string is exposed [edit] See also prints to stdout or a file stream using formatted representation of the arguments
(function template) [edit] same as std::print except that each print is terminated by additional new line
(function template) [edit] outputs formatted representation of the arguments
(function template) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4