SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
C++ New Added 9 October 2026

C++: error: 'format' is not a member of 'std'

std::format is C++20 and lives in <format>, which needs both the C++20 flag and a recent enough standard library: GCC 13, Clang 17 with libc++, or Visual Studio 2019 16.10. GCC still defaults to C++17, so one build file without the flag is enough. On macOS the deployment target matters as well as the Xcode version, which is why the same code builds for one target and not another.

Quick fix

Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.

Quick fix
# Does this toolchain have <format> at all?
g++ --version
echo | g++ -x c++ -std=c++20 -dM -E -include format - | grep __cpp_lib_format

#include <format>
std::string s = std::format("{} items", n);

# Set the standard explicitly
g++ -std=c++20 main.cpp
# CMake
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Stuck on an older toolchain? {fmt} has the same API:
#   fmt::format("{} items", n), with find_package(fmt) and fmt::fmt

How to diagnose C++ errors

C++ errors fall into two very different worlds. Compile and link errors (undefined reference, multiple definition, template substitution failure) are deterministic and are almost always about declarations, the One Definition Rule, or link order. Runtime memory errors (segfaults, double free, use-after-free) are non-deterministic and should never be debugged by reading code alone; a sanitizer will find in seconds what code review misses for days.

If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.

  1. Rebuild with sanitizers before anything else: -fsanitize=address,undefined -fno-omit-frame-pointer -g. AddressSanitizer reports the exact allocation and free sites for use-after-free and double-free.
  2. For undefined-reference errors, check link order, remembering that with GNU ld libraries must come after the objects that use them, and check for a C/C++ linkage mismatch that needs extern "C".
  3. Use nm -C libfoo.a | grep symbol to confirm the symbol is actually present and to see the demangled signature. A signature that differs by a const is a different symbol.
  4. Enable core dumps (ulimit -c unlimited) and open them in gdb with gdb ./binary core, then bt full. A stack trace beats speculation.
  5. For template errors, read the message from the bottom up. The final line is usually the real constraint that failed; everything above is instantiation context.

Tools worth reaching for

  • -fsanitize=address,undefined
  • valgrind
  • gdb / lldb
  • nm -C
  • ldd

Authoritative references

Primary documentation for this error, worth reading before applying any fix in production.

en.cppreference.com en.cppreference.com

Related C++ errors

See all 20 C++ errors →

Browse other categories

Something missing or wrong?

This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.