Having Fun with Modern C++ -- Daniel Lemire

Jb7DBcxe_400x400.jpgRecent versions of the C++ language (C++20 and C++23) may allow you to change drastically how you program in C++. I want to provide some fun examples.

Having Fun with Modern C++

by Daniel Lemire

From the article:

Thanks to the integration of the features from the popular fmt library, it is much easier to format strings elegantly in C++. In turn the fmt library was inspired by the work done in languages like Python.

Suppose that you have a vector of integers and you want to print its content:

std::vector<int> v = {1, 2, 3, 4, 5};
std::println("{}", v);

Suppose you want it to be centered in a line of 40 characters, with underscore characters around it:

std::vector<int> v = {1, 2, 3, 4, 5};
std::println("{:_^40}", v);
// ____________[1, 2, 3, 4, 5]_____________

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.