C++

'std::print' Is Not a Member of 'std' Fix

std::print and std::println are C++23 library functions, not language features: the compiler can fully support C++23 and still have no std::print, because the function lives in the header of the standard library — and in libstdc++ that header only arrived with GCC 14. Read the first line of your error: it tells you whether the header is missing entirely or merely not included.

Written November 27, 2026 · Tested with GCC 13.3.0 · 10 min read

By the end of this guide
  • The error: the header is not there
  • The error: 'print' is not a member of 'std'
  • The real fix on GCC: version 14 or newer
  • The fallback that keeps the format string: std::format plus std::cout

Written November 27, 2026

Tested with GCC 13.3.0

What this guide is

std::print and std::println are formatted-output functions defined in the header <print>, available since C++23. std::println formats its arguments into the {} placeholders of a format string — the same format syntax as std::format — and writes the result to stdout, with a newline appended; std::print is the same function without the appended newline. Both also have overloads that take a FILE* as the first argument and write there instead.

Because the functions live in a library header, two different defects produce two different errors, and they have different fixes:

  • The header itself is absent from your standard library. The compiler stops at the #include line: fatal error: print: No such file or directory. No flag fixes this — the library is too old.
  • The header exists on your system, but the name is not declared in your translation unit: 'print' is not a member of 'std'. Either the #include <print> line is missing, or the file was compiled below C++23 mode, where the header defines nothing.

In libstdc++, the library shipped with GCC, formatted output (proposal P2093R14) arrived in GCC 14.1, with the feature-test macro __cpp_lib_print >= 202207L. Every GCC before 14 — including the widely shipped GCC 13 — has no <print> header at all, no matter which -std flag you pass. That is the whole diagnosis for most readers: check g++ --version first, and only debug includes and flags if it reports 14 or newer.

The error: the header is not there

This is the smallest program that uses the feature:

C++
#include <print>

int main() {
    std::println("Hello, {}!", "world");
    std::print("No newline here");
    return 0;
}

Compiled with GCC 13.3.0 in C++23 mode, it fails on the include line:

Terminal
$ g++ -std=c++23 print.cpp -o print_prog
print.cpp:1:10: fatal error: print: No such file or directory
    1 | #include <print>
      |          ^~~~~~~
compilation terminated.

The flag is not the problem. The same command with no -std flag, and the same command with -std=c++20, print the identical fatal error, because the file print does not exist in the GCC 13 header directory for the preprocessor to find in any mode. Clang fails the same way when it is paired with this library — the header comes from the standard library, not from the compiler front end:

Terminal
$ clang++ -std=c++23 print.cpp -o print_prog
print.cpp:1:10: fatal error: 'print' file not found
    1 | #include <print>
      |          ^~~~~~~
1 error generated.

The fix for this shape is a newer library, covered below — or one of the fallbacks, which need nothing new.

The error: 'print' is not a member of 'std'

The second message appears when the name std::print is used in a file where nothing declared it. The smallest case is a missing include:

C++
#include <iostream>

int main() {
    std::print("Hello!\n");
    return 0;
}
Terminal
$ g++ -std=c++23 noinclude.cpp -o noinclude_prog
noinclude.cpp: In function ‘int main()’:
noinclude.cpp:4:10: error: ‘print’ is not a member of ‘std’; did you mean ‘printf’?
    4 |     std::print("Hello!\n");
      |          ^~~~~
      |          printf

On a toolchain new enough to have the header — GCC 14 or newer for libstdc++ — this same message is what a missing #include <print> produces, and it is also what compiling below C++23 mode produces: the libstdc++ manual lists <print> among the C++ 2023 library headers, available in C++23 compilation mode, and including a C++23 header in an earlier mode does not define anything from it. So on a new-enough toolchain the fix is exactly two things, in this order:

C++
#include <print>
Command
$ g++ -std=c++23 print.cpp -o print_prog

If both are already right and the error persists, do not change the code again — settle which library your compiler is actually using with the feature-test macro check in the checklist: a new compiler paired with an older libstdc++ (or with a different standard library that has no <print>) produces this shape even when the compiler version looks new enough.

The real fix on GCC: version 14 or newer

std::print is a library feature, so the compiler version that matters is the library's. GCC's own C++ standards support page enables C++23 language support with -std=c++23 from GCC 11 onward, but the library half is tracked separately in the libstdc++ implementation status, and its "Formatted output" row — proposal P2093R14 — reads GCC 14.1. GCC 11, 12, and 13 accept the -std=c++23 flag and implement much of C++23, and none of them can compile a program that includes <print>.

So the upgrade rule is exact: GCC 14 or newer, compiled with -std=c++23 (or -std=gnu++23), with #include <print> in the file. Anything less gets one of the two errors above, and no combination of flags, include paths, or linking options changes that.

The fallback that keeps the format string: std::format plus std::cout

An older GCC is not uniformly old. libstdc++ added std::format in GCC 13.1, a full release cycle before <print> existed, so a GCC 13 program can keep the {} format-string style and only give up the one-call printing:

C++
#include <format>
#include <iostream>
#include <string>

int main() {
    std::string name = "world";
    std::cout << std::format("Hello, {}!\n", name);
    std::cout << std::format("No newline here");
    return 0;
}
Terminal
$ g++ -std=c++20 format.cpp -o format_prog
$ ./format_prog
Hello, world!
No newline here

std::format returns the formatted text as a std::string, and std::cout writes it. The newline that std::println would have appended goes into the format string explicitly, as \n. This fallback already works in C++20 mode, and it is the smallest edit to make to code written for std::print: keep every format string, change only the delivery.

The plain fallbacks: std::cout and std::printf

Two older routes need no C++20 feature at all. Stream output with std::cout:

C++
#include <iostream>
#include <string>

int main() {
    std::string name = "world";
    std::cout << "Hello, " << name << "!\n";
    std::cout << "No newline here";
    return 0;
}

And C-style formatted output with std::printf, declared in <cstdio> — the function GCC's own diagnostic suggests in the error above:

C++
#include <cstdio>
#include <string>

int main() {
    std::string name = "world";
    std::printf("Hello, %s!\n", name.c_str());
    std::printf("No newline here");
    return 0;
}

Both programs, compiled with g++ -std=c++23 under GCC 13.3.0, print exactly what the std::println / std::print pair was written to print:

Output
Hello, world!
No newline here

The differences to respect when converting: std::printf uses % conversions instead of {} placeholders, and a std::string argument must be passed as name.c_str(); std::cout takes each piece with its own << and has no placeholders at all. Neither checks a format string against the argument types the way std::print does.

One file for both worlds: guard on __has_include

Code that must build on old and new toolchains can pick its route at compile time. __has_include(<print>) is true only where the header exists:

C++
#include <iostream>
#include <string>

#if __has_include(<print>)
#include <print>
#define HAVE_PRINT 1
#else
#define HAVE_PRINT 0
#endif

int main() {
    std::string name = "world";
#if HAVE_PRINT
    std::println("Hello, {}!", name);
    std::print("No newline here");
#else
    std::cout << "Hello, " << name << "!\n";
    std::cout << "No newline here";
#endif
    return 0;
}

Under GCC 13.3.0 this compiles with -std=c++23 and runs the std::cout branch, printing the same two lines; on a library with <print> it compiles the std::println branch instead. The guard tests the thing that is actually missing — the header — rather than a compiler version number, so it stays correct across GCC, Clang with libstdc++, and Clang with libc++.

The exact rule

  • std::print and std::println are declared by #include <print>, in C++23 mode, and nowhere else. There is no declaration to find in <iostream>, <cstdio>, or any other header.
  • In libstdc++, <print> exists from GCC 14.1 onward. GCC 13 and older do not have the header in any mode: the error is fatal error: print: No such file or directory, and the only fixes are a newer library or a fallback.
  • Where the header exists, 'print' is not a member of 'std' means the declaration never reached your file: the include is missing, or the mode is below C++23.
  • The feature-test macro is the ground truth for a given build: __cpp_lib_print >= 202207L, defined by <version>, is present exactly when the library provides the print functions.

The fixes, ranked

  • First, on GCC 14 or newer: add #include <print> and compile with -std=c++23. This is the complete fix whenever the library is new enough, and both halves are required.
  • Second, on GCC 13 or older, if the machine can be upgraded: move to GCC 14 or newer. The header arrives with the library; there is no package that adds <print> to the libstdc++ of GCC 13.
  • Third, on a compiler that must stay: keep the format strings and switch the delivery to std::cout << std::format(...). On GCC 13 this works in C++20 mode and is the closest fallback to the original code.
  • Fourth, where even <format> is unavailable or the code is simple: std::cout chains, or std::printf with % conversions and c_str() for strings.
  • Fifth, for code that must build in both worlds: the __has_include(<print>) guard, with std::println in one branch and a fallback in the other.

Which fix for which cause

Cause Message Fix
libstdc++ older than GCC 14 fatal error: print: No such file or directory Upgrade to GCC 14+, or use a fallback
Clang paired with an old libstdc++ fatal error: 'print' file not found Upgrade the library, or use a fallback
#include <print> missing 'print' is not a member of 'std' Add #include <print>
Mode below C++23 on GCC 14+ 'print' is not a member of 'std' Compile with -std=c++23
{} formatting needed on GCC 13 No <print>; <format> is present std::cout << std::format(...)
One file for old and new toolchains Either message, depending on the machine Guard with __has_include(<print>)

Checklist

  • Read the first line of the error before anything else. fatal error: print: No such file or directory is a library-version problem; 'print' is not a member of 'std' is an include-or-mode problem on a new-enough library.
  • Run g++ --version. Below 14, no flag or include change can make std::print compile under libstdc++ — go straight to an upgrade or a fallback.
  • On GCC 14 or newer, check the two basics in order: #include <print> present in the file, and -std=c++23 (or -std=gnu++23) on the command line.
  • Settle any remaining doubt with the feature-test macro: include <version> and test __cpp_lib_print. On GCC 13.3.0 it is not defined, while __cpp_lib_format is defined as 202110 — which is why the std::format fallback works there and std::print does not.
  • When converting to std::printf, convert every {} placeholder to a % conversion and pass each std::string as .c_str(). A placeholder left behind prints literally and passes the wrong arguments.
  • When converting to the std::format fallback, put the newline std::println was adding into the format string yourself — std::print and std::format append nothing.
  • After the fix, confirm the output, not just the compile: the programs here end with Hello, world! on its own line, followed by No newline here with no trailing newline.

Sources

  • GCC, libstdc++ Implementation Status — for formatted output (P2093R14) arriving in GCC 14.1 with __cpp_lib_print >= 202207L, and for std::format improvements (P2216R3) arriving in GCC 13.1.
  • GCC, C++ Standards Support in GCC — for C++23 support being enabled with -std=c++23, and for library implementation status living in the libstdc++ manual rather than on the language page.
  • GCC, libstdc++ Manual — Headers — for <print> being listed among the C++ 2023 library headers, available in C++23 compilation mode, with earlier modes not defining anything from them.
  • cppreference, std::println — for std::println and std::print being defined in the header <print> since C++23, for println appending a newline where print does not, and for the __cpp_lib_print value 202207L.

Keep Exploring