C++
'std::chrono' Is Not a Member of 'std' Fix
std::chrono lives in one header,
Written November 29, 2026 · Tested with GCC 13.3.0 · 10 min read
- The rule underneath: one header, C++11 or later
- The first failure: no <chrono> include
- The second failure: <chrono> included, compiled as C++98
- The header sweep: two headers rescue by accident, four do not
Written November 29, 2026
Tested with GCC 13.3.0
What this guide is
The error on a std::chrono name means the compiler has no chrono namespace inside std to look the name up in. The common cause is a missing include: nothing in the file included <chrono>, the header that declares the namespace, so a std::chrono:: name used in a function body fails with 'std::chrono' has not been declared. The second cause is the language mode: the chrono library is since C++11, so a file compiled in an older mode gets no std::chrono names either - but that shape announces itself differently, with a #error from inside the header, and this guide reproduces both shapes so each is recognizable on sight.
Between the two sits a trap this guide also covers: some other headers pull the chrono declarations in as a side effect. A program that uses std::chrono::steady_clock without including <chrono> can compile anyway when <thread> or <mutex> is present, and fail the day either include is removed. The fix is never the lucky header - it is #include <chrono> in the file itself, plus a language mode of C++11 or later.
The rule underneath: one header, C++11 or later
The Date and time library page dates the whole library: the Chrono library is since C++11, defining clocks, time points and durations, all of them in namespace std::chrono and defined in header <chrono> - system_clock, steady_clock and high_resolution_clock are each marked (C++11), as are the time_point and duration class templates. There is no C++98 form of std::chrono: the library arrived with the 2011 standard.
The std::chrono: the duration and time_point class templates, the duration_cast conversion, the convenience typedefs nanoseconds, microseconds, milliseconds, seconds and the rest, and the clock classes. The std::chrono::steady_clock page gives the clock this guide uses the same date: class steady_clock since C++11, a monotonic clock whose time points cannot decrease as physical time moves forward, most suitable for measuring intervals, with the static member function now() returning a time_point representing the current value of the clock. So a std::chrono name needs both conditions at once: the header included, so the declarations are in the file, and a language mode of C++11 or later, so the header is allowed to declare them.
The first failure: no <chrono> include
This program reads the current time from std::chrono::steady_clock and includes only <iostream>:
#include <iostream>
int main() {
auto t = std::chrono::steady_clock::now();
std::cout << "tick\n";
return 0;
}
$ g++ -std=c++17 p1_fail_no_include.cpp -o p1_fail_no_include
p1_fail_no_include.cpp: In function 'int main()':
p1_fail_no_include.cpp:4:19: error: 'std::chrono' has not been declared
4 | auto t = std::chrono::steady_clock::now();
| ^~~~~~
Read the error's subject: it names std::chrono itself, not steady_clock and not now. The namespace was never declared, so the compiler stops at the first component of the qualified name and never gets to judge the rest. The language mode here is already C++17 - the mode is not the problem in this shape, the missing header is. One error is the whole cascade in this program, because the failed line is the only use of the name; a file that goes on to use t, or to name more std::chrono:: types, collects follow-on errors that all trace back to this one.
The second failure: <chrono> included, compiled as C++98
The same use of the clock with the header included still fails when the language mode is older than the library - and the diagnostic is not the one above:
#include <chrono>
#include <iostream>
int main() {
auto t = std::chrono::steady_clock::now();
std::cout << "tick\n";
return 0;
}
$ g++ -std=c++98 p2_fail_cpp98.cpp -o p2_fail_cpp98
In file included from /usr/include/c++/13/chrono:38,
from p2_fail_cpp98.cpp:1:
/usr/include/c++/13/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
32 | #error This file requires compiler and library support \
| ^~~~~
p2_fail_cpp98.cpp: In function 'int main()':
p2_fail_cpp98.cpp:5:10: error: 't' does not name a type; did you mean 'tm'?
5 | auto t = std::chrono::steady_clock::now();
| ^
| tm
The first error is raised inside the library's own headers, before any of the program's lines are judged: GCC's <chrono> refuses a pre-C++11 mode outright, with a #error that names the remedy - enable -std=c++11 or -std=gnu++11. The second error is fallout of a different kind: in C++98 mode auto is not the type-deduction keyword, so the declaration line itself does not parse as a declaration. Neither error is the 'std::chrono' has not been declared of the first shape, which is why the two shapes have to be told apart by their first line, not by the title of this guide: a #error mentioning the ISO C++ 2011 standard means the mode is too old, full stop. Raise the mode and the same file compiles unchanged - at both -std=c++11 and -std=c++14 this exact program compiles and prints tick.
The header sweep: two headers rescue by accident, four do not
A missing standard name is sometimes rescued by accident, when another header happens to include the one that declares it. For std::chrono the sweep splits, and the split is the point. This program - the first failure's program with <thread> in place of nothing, still no <chrono> - compiles:
#include <thread>
#include <iostream>
int main() {
auto t = std::chrono::steady_clock::now();
std::cout << "tick\n";
return 0;
}
$ g++ -std=c++17 sweep_thread.cpp -o sweep_thread
$ ./sweep_thread
tick
<mutex> in the same position also compiles the program. Both headers deal in waiting and timing, and in this standard library they bring the chrono declarations in with them, so the std::chrono names resolve even though <chrono> was never included. That is a property of these particular headers in this library implementation, scoped to the names this program uses - steady_clock and now - not a promise about any other chrono name, and not a reason to leave the include out: a file that compiles only because a neighbor pulled its declarations in breaks when the neighbor is removed or the library changes.
The rest of the sweep does not rescue. Replacing the added header with <vector> fails with the same first error as the missing-include shape:
#include <vector>
#include <iostream>
int main() {
auto t = std::chrono::steady_clock::now();
std::cout << "tick\n";
return 0;
}
$ g++ -std=c++17 sweep_vector.cpp -o sweep_vector
sweep_vector.cpp: In function 'int main()':
sweep_vector.cpp:5:19: error: 'std::chrono' has not been declared
5 | auto t = std::chrono::steady_clock::now();
| ^~~~~~
The same program was compiled with each of <string>, <algorithm> and <iostream> as the only candidate header, at C++17: every one fails with the same first error, 'std::chrono' has not been declared. So of the six headers probed in place of <chrono>, two - <thread> and <mutex> - rescue this program and four do not. Neither outcome changes the repair: include <chrono> directly in every file that names std::chrono:: types, rather than relying on a transitive rescue that the file does not state.
The fix: include <chrono> and compile at C++11 or later
Both halves together - the header included, the mode at C++11 - and the library is fully usable. This program times a 20-millisecond sleep with steady_clock and reports how long it actually took:
#include <chrono>
#include <iostream>
#include <thread>
int main() {
auto start = std::chrono::steady_clock::now();
std::this_thread::sleep_for(std::chrono::milliseconds(20));
auto end = std::chrono::steady_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "elapsed " << ms.count() << " ms\n";
std::cout << "at least 20 " << (ms.count() >= 20) << "\n";
return 0;
}
$ g++ -std=c++11 p4_fix.cpp -o p4_fix
$ ./p4_fix
elapsed 20 ms
at least 20 1
Every name that failed before now resolves: steady_clock::now() returns the two time_point values, subtracting them gives a duration, and duration_cast converts it to milliseconds, whose count() is the number to print - the pieces the header page lists, assembled in the order the steady_clock page describes for measuring intervals. The elapsed number is a measurement, not a constant: the sleep asks for 20 milliseconds, so the count is at least 20, and on a busy machine it can come out higher - the second line is the part that always holds. Note the division of labor in the includes: <chrono> provides the clock, the duration and the conversion, while the sleeping itself is std::this_thread::sleep_for from <thread>, given a chrono duration as its argument - the two headers cooperate here by design, which is different from the sweep's accident, where <thread> was silently doing <chrono>'s job.
Neighboring error: a member steady_clock does not have
Once <chrono> is included and the mode is right, a wrong member name produces a different error on a different subject. steady_clock has now(); it has no later(), so asking for it fails like this:
#include <chrono>
#include <iostream>
int main() {
auto t = std::chrono::steady_clock::later();
std::cout << "tick\n";
return 0;
}
$ g++ -std=c++17 p5_neighbour_no_member.cpp -o p5_neighbour_no_member
p5_neighbour_no_member.cpp: In function 'int main()':
p5_neighbour_no_member.cpp:5:41: error: 'later' is not a member of 'std::chrono::_V2::steady_clock'
5 | auto t = std::chrono::steady_clock::later();
| ^~~~~
The contrast separates the two errors cleanly. This error names the class - std::chrono::_V2::steady_clock, GCC's internal spelling of std::chrono::steady_clock - and the missing member, which proves the namespace and the class were both found: the include and the mode are already right, and only the member name is wrong. The title error names std::chrono itself, because the namespace was never there to be searched. The repair here is the real member, std::chrono::steady_clock::now(), exactly as the fixed program above calls it.
Neighboring error: a time point is not a duration
The other neighboring fault mixes up the library's two central types. A time_point is a moment; a duration is a span between moments. Assigning one to the other is not a conversion the library defines, so it fails at the assignment:
#include <chrono>
#include <iostream>
int main() {
std::chrono::steady_clock::time_point t;
std::chrono::milliseconds ms = t;
std::cout << ms.count() << "\n";
return 0;
}
$ g++ -std=c++17 p6_neighbour_mismatch.cpp -o p6_neighbour_mismatch
p6_neighbour_mismatch.cpp: In function 'int main()':
p6_neighbour_mismatch.cpp:6:36: error: conversion from 'std::chrono::_V2::steady_clock::time_point' {aka 'std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long int, std::ratio<1, 1000000000> > >'} to non-scalar type 'std::chrono::milliseconds' {aka 'std::chrono::duration<long int, std::ratio<1, 1000> >'} requested
6 | std::chrono::milliseconds ms = t;
| ^
Nothing in this error says a name is missing - both types are spelled out in full, because both were found and declared. The fault is the operation: a duration comes from subtracting two time points, as the fixed program does with end - start, and duration_cast then converts that duration to the unit wanted. When an error names complete std::chrono types on both sides of a conversion, read it as a type mix-up in the code, not as an include or mode problem - adding headers cannot fix it.
Decision summary
- The first error is
'std::chrono' has not been declaredand the file has no<chrono>include: add#include <chrono>- every later error in the cascade traces to the missing namespace. - The first error is a
#errorabout compiler and library support for the ISO C++ 2011 standard, raised from inside the library headers: the language mode is older than C++11 - the compile line shows-std=c++98or an equivalent setting; compile at-std=c++11or later instead of changing code. - The program compiles without
<chrono>because another header is pulling the chrono declarations in -<thread>or<mutex>in the sweep above, and other timing-related headers can do the same: that is a transitive rescue, scoped to the names used - add<chrono>anyway, so the file states its own dependency and survives the other include being removed. - The program includes some other header that sounds related -
<vector>,<string>,<algorithm>or<iostream>: none of them declaresstd::chrono; the probed sweep found no rescue from any of the four, so add<chrono>itself. - The error instead names the class, as in
'later' is not a member of 'std::chrono::_V2::steady_clock': the namespace was found and the member name is wrong -steady_clock's member isnow(). - The error is a conversion failure naming a
time_pointtype on one side and adurationtype such asstd::chrono::millisecondson the other: a moment was used where a span belongs - subtract two time points to get a duration, thenduration_castit.
Checklist
- The file includes
<chrono>itself - not a neighboring header in its place, and not a transitive rescue through another header such as<thread>or<mutex>- before anystd::chrono::name is used. - The compile line, or the build system's language standard setting, is C++11 or later; a pre-C++11 mode makes the header stop with its own
#errorbefore the program is judged. - The first error is read before the cascade: errors about the variable that failed to declare, or about later uses, disappear when the namespace error at the top is fixed.
- A
'has not been declared'wording and a#errorabout the ISO C++ 2011 standard are treated as the two shapes of the same absence - missing header in the first, too-old mode in the second. - Moments and spans are kept apart:
time_pointvalues come from a clock'snow(),durationvalues come from subtracting time points or from the typedefs such asmilliseconds, andduration_castconverts between duration units. - The fixed program compiles at C++11, runs, and its output shows the measured interval at or above the 20 milliseconds that were slept.
Related guides
- 'std::filesystem' Is Not a Member of 'std' Fix - the same missing-namespace fault on the filesystem library:
std::filesystemis declared by<filesystem>, and because that library is C++17, it fails in both shapes - missing include, and a mode that is too old for it. - 'std::vector' Is Not a Member of 'std' Fix - the same missing-namespace fault on a container:
std::vectoris declared by<vector>, and the repair is that header plus a mode the type exists in. - 'std::optional' Is Not a Member of 'std' Fix - the closest sibling in shape:
std::optionalis a C++17 addition living in its own header,<optional>, so its missing-include and too-old-mode failures mirror the pair covered here.
Sources
- cppreference.com, Date and time library — the library's date and contents: the Chrono library is since C++11, its clocks
system_clock,steady_clockandhigh_resolution_clockare each (C++11), defined in header<chrono>and in namespacestd::chrono, alongside thetime_pointanddurationclass templates - which is why a pre-C++11 mode has nostd::chrononames at all. - cppreference.com, Standard library header
(C++11) — what the header declares: thedurationandtime_pointclass templates,duration_cast, the convenience typedefsnanosecondsthroughhours, and the clock classes, all in namespacestd::chrono- the declarations a file gets only by including<chrono>itself (or, for some names, by a neighbor's transitive include, which the sweep section measures). - cppreference.com, std::chrono::steady_clock — the clock at the center of the error:
class steady_clocksince C++11, a monotonic clock whose time points cannot decrease as physical time moves forward, most suitable for measuring intervals, withnow()as its member function returning the current time point - and nolater()among its members, which is the boundary the neighboring-error section draws.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.