Skip to content
Tech News
← Back to articles

Improvements to Std:Format in C++26

read original more articles
Why This Matters

The C++26 standard introduces significant enhancements to the std::format library, simplifying common tasks such as printing empty lines, formatting pointers, and handling filesystem paths. These improvements streamline coding practices, reduce workarounds, and enhance code readability and maintainability for developers and consumers alike.

Key Takeaways

The C++26 standard features a series of improvements to the format library. In this article, we will look at the most important of them.

Printing an empty line

Prior to C++26, printing an empty line had to be done like this:

std::print("

");

In C++26, std::println has an overload without any parameters that prints a new line to the console.

std::print();

Formatting pointers

Formatting pointer types was not available directly, it required a hack: reinterpreting the pointer type as an integer type in order to print it.

int i = 0; const void* p = &i; std::println("{:#018x}", reinterpret_cast<uintptr_t>(p));

... continue reading