not a member of std C/C++ Origin: Application & API C++11 to C++23 Last updated 15 Oct 2026

C++: error: 'optional' in namespace 'std' does not name a template type — wrong -std standard

The standard-library feature you used needs a newer C++ standard than the compiler is currently set to.

Exact message you may see in namespace 'std' does not name a type'optional' in namespace 'std' does not name a template type'string_view' is not a member of 'std'no member named 'format' in namespace 'std''filesystem' is not a member of 'std'
Seen on: C/C++ GCC Clang CMake

Meaning

std::optional, std::string_view, std::filesystem (C++17), std::span, std::format (C++20) and many others exist only when compiling with the matching -std= flag. Old compilers default to C++98/11/14. Set the standard in your build system and make sure the compiler is new enough.

Common causes

  • Compiler default standard is older than the feature (GCC before 11 defaults to C++14)
  • -std=c++11 hard-coded in a Makefile or CMake
  • Compiler too old to support the feature
  • Missing the header (<optional>, <string_view>) as well

⚡ Quick fix

  1. Compile with -std=c++17 (or c++20)
  2. Set CMAKE_CXX_STANDARD in CMake
  3. Update the compiler if it still fails

Detailed fix by platform

GCC / Clang

  1. g++ -std=c++20 main.cpp -o app — check g++ --version (GCC 11+ for most of C++20)
  2. With Clang on Linux install a newer clang and libstdc++

CMake

  1. Set set(CMAKE_CXX_STANDARD 20), set(CMAKE_CXX_STANDARD_REQUIRED ON) and set(CMAKE_CXX_EXTENSIONS OFF)

Code examples

Choosing the C++ standard

cmake
cmake_minimum_required(VERSION 3.16)
project(app LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(app main.cpp)
# or per target: target_compile_features(app PRIVATE cxx_std_20)

How to diagnose

  1. Standard — Which -std does the build use? (compile with -v)
  2. Compiler — Is the version new enough?
  3. Header — Is the header included?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Could not find a package configuration file — CMake Error: Could not find a package configuration file provided by "Foo" (requested version 1.2) (C/C++)Could not find a pack…does not name a type — C++: error: 'string' does not name a type (C/C++)does not name a typefatal error: No such file or directory — C/C++: fatal error: foo.h: No such file or directory — #include not found (C/C++)fatal error: No such …missing separator — Make: Makefile:5: *** missing separator. Stop. (spaces instead of a tab) (C/C++)missing separatorNo rule to make target — Make: *** No rule to make target 'foo.c', needed by 'foo.o'. Stop. (C/C++)No rule to make targetredefinition of — C++: error: redefinition of 'class X' / multiple definition — missing include guard (C/C++)redefinition ofwas not declared in this scope — C++: error: 'x' was not declared in this scope (undeclared identifier) (C/C++)was not declared in t…not a mem…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.