September 11, 2025Sep 11 I recently published two posts about how C++26 improves std::format and the related facilities. (If you missed them, here are Part 1 and Part 2). Now itâs time to explore how you can format your own types using std::format. Format your own type (Part 1) by Sandor Dargo From the article: std::format was introduced in C++20 and is based on Victor Zverovichâs <fmt> library, which in turn was inspired by Pythonâs string formatting capabilities. Letâs skip the fancy formatting options and simply see how to interpolate values using std::format. #include <format> #include <iostream> #include <string> int main() { std::string language{"C++"}; int version{20}; std::cout << std::format("{}{} is fun", language, version) << '\n'; } /* C++20 is fun */ That was easy. Now imagine you want to print your own type. That wonât work by default. View the full article
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.