{"id":33,"date":"2026-02-20T21:53:17","date_gmt":"2026-02-20T13:53:17","guid":{"rendered":"https:\/\/blog.mirpri.com\/?p=33"},"modified":"2026-02-22T19:03:45","modified_gmt":"2026-02-22T11:03:45","slug":"the-new-stdprint-in-c23-a-modern-replacement-for-cout-and-printf","status":"publish","type":"post","link":"https:\/\/blog.mirpri.com\/index.php\/the-new-stdprint-in-c23-a-modern-replacement-for-cout-and-printf\/","title":{"rendered":"The New std::print in C++23: A Modern Replacement for cout and printf"},"content":{"rendered":"\n<p>For decades, C++ developers have relied on two main ways to print output:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>std::cout<\/code> (from iostream)<\/li>\n\n\n\n<li><code>printf<\/code> (from C)<\/li>\n<\/ul>\n\n\n\n<p>But in <strong>C++23<\/strong>, we finally get something modern:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;print&gt;\n\nstd::print(\"Hello, {}\\n\", name);\n<\/code><\/pre>\n\n\n\n<p>Yes \u2014 C++ now has a built-in, type-safe, Python-style printing function.<\/p>\n\n\n\n<p>Let\u2019s explore what <code>std::print<\/code> is, why it matters, and how it compares to older methods.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is <code>std::print<\/code>?<\/h2>\n\n\n\n<p><code>std::print<\/code> is introduced in C++23 via the <code>&lt;print&gt;<\/code> header.<\/p>\n\n\n\n<p>It is based on the formatting system from <code>&lt;format&gt;<\/code> (introduced in C++20), which itself was inspired by Python\u2019s formatting style.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;print&gt;\n\nint main() {\n    std::string name = \"Alice\";\n    int age = 20;\n\n    std::print(\"Name: {}, Age: {}\\n\", name, age);\n}<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Name: Alice, Age: 20<\/code><\/pre>\n\n\n\n<p>Notice:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>{}<\/code> placeholders<\/li>\n\n\n\n<li>Automatic type safety<\/li>\n\n\n\n<li>Clean and readable formatting<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comparing <code>std::print<\/code> with Older Methods<\/h2>\n\n\n\n<p>Let\u2019s compare it side by side.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1\ufe0f\u20e3 <code>std::cout<\/code> (Traditional C++ Way)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>std::cout &lt;&lt; \"Name: \" &lt;&lt; name &lt;&lt; \", Age: \" &lt;&lt; age &lt;&lt; std::endl;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Pros<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Type safe<\/li>\n\n\n\n<li>Fully C++<\/li>\n\n\n\n<li>Works everywhere<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Cons<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Verbose<\/li>\n\n\n\n<li>Hard to format complex strings<\/li>\n\n\n\n<li>Slower due to stream overhead<\/li>\n\n\n\n<li>Chaining with <code>&lt;&lt;<\/code> becomes messy<\/li>\n<\/ul>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>std::cout &lt;&lt; std::setw(10) &lt;&lt; std::setprecision(2) &lt;&lt; value;\n<\/code><\/pre>\n\n\n\n<p>Formatting quickly becomes ugly.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2\ufe0f\u20e3 <code>printf<\/code> (C Style)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>printf(\"Name: %s, Age: %d\\n\", name.c_str(), age);\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Pros<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Fast<\/li>\n\n\n\n<li>Concise formatting<\/li>\n\n\n\n<li>Familiar to C developers<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Cons<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Not type safe<\/li>\n\n\n\n<li>Easy to cause undefined behavior<\/li>\n\n\n\n<li>Requires manual conversion (<code>c_str()<\/code>)<\/li>\n\n\n\n<li>Format string errors are not caught at compile time<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3\ufe0f\u20e3 <code>std::format<\/code> (C++20)<\/h3>\n\n\n\n<p>Before <code>std::print<\/code>, we got:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;format&gt;\n\nstd::string s = std::format(\"Name: {}, Age: {}\", name, age);\nstd::cout &lt;&lt; s &lt;&lt; '\\n';\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Pros<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Type safe<\/li>\n\n\n\n<li>Modern formatting<\/li>\n\n\n\n<li>Very clean syntax<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Cons<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Requires extra step (format \u2192 then output)<\/li>\n\n\n\n<li>Slightly more verbose<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4\ufe0f\u20e3 <code>std::print<\/code> (C++23 Modern Way)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>std::print(\"Name: {}, Age: {}\\n\", name, age);\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Pros<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Type safe<\/li>\n\n\n\n<li>Concise<\/li>\n\n\n\n<li>Modern formatting<\/li>\n\n\n\n<li>No stream chaining<\/li>\n\n\n\n<li>No C-style format specifiers<\/li>\n\n\n\n<li>Cleaner and more readable<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Cons<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Requires C++23<\/li>\n\n\n\n<li>Compiler support still evolving<\/li>\n\n\n\n<li>Not yet universally available in all toolchains<\/li>\n<\/ul>\n\n\n\n<p><mark style=\"background-color:#FFEE58\" class=\"has-inline-color\"><strong>MinGW<\/strong> on Windows doesn&#8217;t seem to support <code>print<\/code> yet! But clang and msvc works fine.<\/mark><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Performance Comparison (Conceptually)<\/h2>\n\n\n\n<p>In general:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>printf<\/code> \u2192 Fast<\/li>\n\n\n\n<li><code>std::cout<\/code> \u2192 Slower (stream overhead)<\/li>\n\n\n\n<li><code>std::print<\/code> \u2192 Designed to be fast and modern<\/li>\n<\/ul>\n\n\n\n<p><code>std::print<\/code> avoids iostream\u2019s heavy machinery and builds on the efficient formatting engine of <code>&lt;format&gt;<\/code>. For many use cases, it offers both safety and performance.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why <code>std::print<\/code> Matters<\/h2>\n\n\n\n<p><code>std::print<\/code> represents something bigger:<\/p>\n\n\n\n<p>C++ is modernizing.<\/p>\n\n\n\n<p>For years, developers complained that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Printing was verbose<\/li>\n\n\n\n<li>Formatting was awkward<\/li>\n\n\n\n<li>C-style formatting was unsafe<\/li>\n\n\n\n<li>Streams were slow and complicated<\/li>\n<\/ul>\n\n\n\n<p>Now, we finally have a clean, safe, expressive solution built into the standard.<\/p>\n\n\n\n<p>It brings C++ closer to languages like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python (<code>print(f\"...\")<\/code>)<\/li>\n\n\n\n<li>Rust (<code>println!<\/code>)<\/li>\n\n\n\n<li>JavaScript (<code>console.log()<\/code>)<\/li>\n<\/ul>\n\n\n\n<p>Without sacrificing type safety.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When Should You Use <code>std::print<\/code>?<\/h2>\n\n\n\n<p>Use it if:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You\u2019re compiling with C++23<\/li>\n\n\n\n<li>Your compiler supports <code>&lt;print&gt;<\/code><\/li>\n\n\n\n<li>You want clean formatting<\/li>\n\n\n\n<li>You want safer alternatives to <code>printf<\/code><\/li>\n\n\n\n<li>You dislike <code>&lt;&lt;<\/code> chaining<\/li>\n<\/ul>\n\n\n\n<p>If you&#8217;re stuck on older standards, <code>std::format + std::cout<\/code> is the closest modern alternative.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p><code>std::print<\/code> is not just another function.<\/p>\n\n\n\n<p>It\u2019s the long-awaited modern printing solution for C++.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Cleaner than <code>std::cout<\/code><\/li>\n\n\n\n<li>Safer than <code>printf<\/code><\/li>\n\n\n\n<li>More direct than <code>std::format<\/code><\/li>\n<\/ul>\n\n\n\n<p>If you\u2019re learning modern C++, it\u2019s worth adopting early.<\/p>\n\n\n\n<p>C++23 finally makes printing elegant. And that\u2019s something many of us have been waiting for.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For decades, C++ developers have relied on two main ways to print output: But in C++23, we finally get something modern: Yes \u2014 C++ now has a built-in, type-safe, Python-style printing function. Let\u2019s explore what std::print is, why it matters, and how it compares to older methods. What Is std::print? std::print is introduced in C++23 [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":43,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[12],"class_list":["post-33","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","tag-c"],"_links":{"self":[{"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/media\/43"}],"wp:attachment":[{"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}