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

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

By the end of this guide
  • The error: the include is missing
  • The same missing include through <iostream>: the same wording
  • The fix
  • Both ends: pushfront, pushback, popfront, popback, and indexed access

Written November 27, 2026

Tested with GCC 13.3.0

What this guide is

std::deque is a class template defined in the header <deque>. It is an indexed sequence container — a double-ended queue — that allows fast insertion and deletion at both its beginning and its end. Unlike std::vector, its elements are not stored contiguously: typical implementations use a sequence of individually allocated fixed-size arrays, with additional bookkeeping, and its storage expands and contracts automatically as needed.

Because the class template lives in one specific header, a missing #include <deque> is the cause behind this error, and for this type GCC words it one way: 'deque' is not a member of 'std', with a note that names the header — 'std::deque' is defined in header '<deque>'; did you forget to '#include <deque>'? That wording is reproduced below, exactly as GCC 13.3.0 prints it. The fix is to add <deque>.

The error: the include is missing

This program declares a std::deque, pushes two values onto its back, and prints its size, but includes only <cstdio>:

C++
#include <cstdio>
int main() {
    std::deque<int> d;
    d.push_back(1);
    d.push_back(2);
    std::printf("%zu\n", d.size());
    return 0;
}
Terminal
$ g++ -std=c++17 cstdio.cpp -o cstdio_prog
cstdio.cpp: In function 'int main()':
cstdio.cpp:3:10: error: 'deque' is not a member of 'std'
    3 |     std::deque<int> d;
      |          ^~~~~
cstdio.cpp:2:1: note: 'std::deque' is defined in header '<deque>'; did you forget to '#include <deque>'?
    1 | #include <cstdio>
  +++ |+#include <deque>
    2 | int main() {
cstdio.cpp:3:16: error: expected primary-expression before 'int'
    3 |     std::deque<int> d;
      |                ^~~
cstdio.cpp:4:5: error: 'd' was not declared in this scope
    4 |     d.push_back(1);
      |     ^

The two errors after the note are knock-on effects of the first one: because the declaration of std::deque was never seen, the compiler cannot parse the declaration of d, and the later use of d has nothing to refer to. The same error and note appear with no includes at all and with only <cstddef> included, and the default compilation mode prints the identical error, so this shape is not a language-mode problem. Fix the first error — the missing include — and the other two disappear with it.

The same missing include through <iostream>: the same wording

Most programs that use std::deque print their results, so <iostream> is usually already included. For some types that changes the wording of the missing-include error; for std::deque it does not. This is the same program with <iostream> and std::cout instead of <cstdio> and std::printf:

C++
#include <iostream>
int main() {
    std::deque<int> d;
    d.push_back(1);
    d.push_back(2);
    std::cout << d.size() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++17 iostream.cpp -o iostream_prog
iostream.cpp: In function 'int main()':
iostream.cpp:3:10: error: 'deque' is not a member of 'std'
    3 |     std::deque<int> d;
      |          ^~~~~
iostream.cpp:2:1: note: 'std::deque' is defined in header '<deque>'; did you forget to '#include <deque>'?
    1 | #include <iostream>
  +++ |+#include <deque>
    2 | int main() {
iostream.cpp:3:16: error: expected primary-expression before 'int'
    3 |     std::deque<int> d;
      |                ^~~
iostream.cpp:4:5: error: 'd' was not declared in this scope
    4 |     d.push_back(1);
      |     ^

The error and the note are identical to the <cstdio> shape: no header in <iostream>'s include chain declares std::deque at all on this toolchain, so there is no second wording to recognize for this type. Whichever output header the file already has, the missing include reads the same way, and the note names the fix.

The neighboring headers split for this type. Three of them rescue the program — it compiles and runs with the header named and no <deque> anywhere in the file:

  • With only <queue> included, the program compiles and runs.
  • With <cstdio> and <queue> included, the program compiles and runs.
  • With <iostream> and <queue> included, the program compiles and runs.
  • With only <stack> included, the program compiles and runs.
  • With <cstdio> and <stack> included, the program compiles and runs.
  • With <iostream> and <stack> included, the program compiles and runs.
  • With only <regex> included, the program compiles and runs.
  • With <cstdio> and <regex> included, the program compiles and runs.
  • With <iostream> and <regex> included, the program compiles and runs.

The rest of the neighbors fail with the same 'deque' is not a member of 'std' error and the same note naming <deque>:

  • With only <vector> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <cstdio> and <vector> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <iostream> and <vector> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With only <list> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <cstdio> and <list> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <iostream> and <list> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With only <string> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <cstdio> and <string> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <iostream> and <string> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With only <algorithm> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <cstdio> and <algorithm> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <iostream> and <algorithm> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With only <utility> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <cstdio> and <utility> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <iostream> and <utility> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With only <memory> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <cstdio> and <memory> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.
  • With <iostream> and <memory> included, the program fails with 'deque' is not a member of 'std' and the note naming <deque>.

The two adaptor rescues have a reason, and it is in the next section: std::queue and std::stack both default their underlying container to std::deque, so their headers have to bring the deque definition with them. The <regex> rescue is different — on this toolchain that header's own implementation pulls the definition in as a side effect. Neither kind of rescue is a promise: no standard header is required to define std::deque on behalf of <deque>, and a program that compiled only because some other header happened to pull the definition in could break under a different library version. The sweep behind this guide went wider than the neighbors: every other standard header probed for this guide — <any>, <array>, <atomic>, <bitset>, <cassert>, <cctype>, <cerrno>, <cfloat>, <chrono>, <climits>, <cmath>, <complex>, <condition_variable>, <cstdarg>, <cstdint>, <cstring>, <ctime>, <exception>, <fstream>, <functional>, <future>, <initializer_list>, <iomanip>, <ios>, <iosfwd>, <istream>, <iterator>, <limits>, <locale>, <map>, <mutex>, <new>, <numeric>, <optional>, <ostream>, <random>, <ratio>, <set>, <sstream>, <stdexcept>, <string_view>, <strstream>, <thread>, <tuple>, <type_traits>, <typeindex>, <typeinfo>, <unordered_map>, <unordered_set>, <valarray>, and <variant> under C++17, the same set under C++20, and <barrier>, <bit>, <charconv>, <compare>, <concepts>, <coroutine>, <filesystem>, <format>, <latch>, <numbers>, <ranges>, <semaphore>, <source_location>, <span>, <stop_token>, <syncstream>, and <version> under C++20 — fails the same way, with the same error and the same note. That is a statement about the headers in that list, on GCC 13.3.0: apart from <queue>, <stack>, and <regex>, none of them rescues this program. Include <deque> in every file that names std::deque.

The fix

Add the header:

C++
#include <deque>
#include <iostream>
int main() {
    std::deque<int> d;
    d.push_back(1);
    d.push_back(2);
    std::cout << d.size() << "\n";
    std::cout << d.front() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++17 good.cpp -o good_prog
$ ./good_prog
2
1

The same program also compiles and runs with no -std flag at all. Two values were pushed, so size prints 2, and front — the first element — prints 1. One include, <deque>, defines the class template.

Both ends: push_front, push_back, pop_front, pop_back, and indexed access

What sets a deque apart from a vector is that both ends are cheap to work with. push_front inserts an element at the beginning and push_back adds one at the end; pop_front and pop_back remove the first and last elements; front accesses the first element and back the last; operator[] accesses an element by index without bounds checking, and at accesses an element by index with bounds checking; size returns the number of elements, and empty checks whether the container is empty:

C++
#include <deque>
#include <iostream>
int main() {
    std::deque<int> d;
    std::cout << d.empty() << "\n";
    d.push_back(20);
    d.push_back(30);
    d.push_front(10);
    std::cout << d.size() << "\n";
    std::cout << d.front() << "\n";
    std::cout << d.back() << "\n";
    std::cout << d[1] << "\n";
    std::cout << d.at(2) << "\n";
    d.pop_front();
    std::cout << d.front() << "\n";
    d.pop_back();
    std::cout << d.back() << "\n";
    std::cout << d.size() << "\n";
    d.pop_front();
    std::cout << d.empty() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++17 behavior.cpp -o behavior_prog
$ ./behavior_prog
1
3
10
30
20
30
20
20
1
1

The deque starts empty, so the first empty prints 1. Two back pushes and one front push build the sequence 10, 20, 30: size prints 3, front prints 10 — the value pushed at the front — and back prints 30. Indexing reaches inside: d[1] prints 20, the middle element, and at(2) prints 30. pop_front removes the 10, so front now prints 20; pop_back removes the 30, so back prints 20 as well and size prints 1. One more pop_front drains the deque, and the final empty prints 1 again. Random access and insertion or removal at either end are all constant-time operations on a deque; insertion or removal in the middle is linear.

Why <queue> and <stack> rescue it: std::deque is their default container

std::queue does not store its elements itself: it is an adaptor wrapped around an underlying container, and that container defaults to std::deque<T>, so std::queue<int> is std::queue<int, std::deque<int>>. std::stack makes the same choice — its underlying container also defaults to std::deque<T>. A header that defines an adaptor defaulted on std::deque cannot leave the deque declaration out, which is why a file that includes only <queue> can name std::deque outright:

C++
#include <iostream>
#include <queue>
int main() {
    std::deque<int> d;
    d.push_back(1);
    d.push_back(2);
    std::cout << d.size() << "\n";
    std::cout << d.front() << "\n";
    std::cout << d.back() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++17 queue_default.cpp -o queue_default_prog
$ ./queue_default_prog
2
1
2

The program never includes <deque>, and it still compiles and runs: size prints 2, front prints 1, and back prints 2, because <queue> brought the full deque definition in to serve as the adaptor's default container. Treat that as a fact about this toolchain, not as a style to copy — the file names std::deque, so the file should include <deque>; relying on the adaptor's header is exactly the side-effect dependency that breaks when a library reorganizes its internals. The <regex> rescue is the same kind of side effect with no adaptor default behind it at all.

A different wording: deque without the std::

Calling the class without its namespace qualifier is a different defect, and GCC words it differently:

C++
#include <deque>
#include <iostream>
int main() {
    deque<int> d;
    d.push_back(1);
    std::cout << d.size() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++17 unqualified.cpp -o unqualified_prog
unqualified.cpp: In function 'int main()':
unqualified.cpp:4:5: error: 'deque' was not declared in this scope
    4 |     deque<int> d;
      |     ^~~~~
unqualified.cpp:4:5: note: suggested alternatives:
In file included from /usr/include/c++/13/deque:66,
                 from unqualified.cpp:1:
/usr/include/c++/13/bits/stl_deque.h:788:11: note:   'std::deque'
  788 |     class deque : protected _Deque_base<_Tp, _Alloc>
      |           ^~~~~
/usr/include/c++/13/deque:83:13: note:   'std::pmr::deque'
   83 |       using deque = std::deque<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~
unqualified.cpp:4:11: error: expected primary-expression before 'int'
    4 |     deque<int> d;
      |           ^~~
unqualified.cpp:5:5: error: 'd' was not declared in this scope
    5 |     d.push_back(1);
      |     ^

'deque' was not declared in this scope is the 'has not been declared' family for this topic: an unqualified name that lookup cannot find at all. This program already includes <deque>, so the include is not the problem — the declaration it adds is std::deque, inside namespace std, and the use must be qualified as std::deque, or the file must bring the name in deliberately. GCC's notes list the suggested alternatives — std::deque itself, and the std::pmr::deque alias the same header declares — and point at the declaration the <deque> header provides. If your error says is not a member of 'std', the name was qualified and the include is the whole problem; if it says was not declared in this scope, check the qualifier first.

The exact rule

  • std::deque is defined by #include <deque>; no other header is required to define it. Of the headers probed for this guide, only <queue>, <stack>, and <regex> bring the definition in on GCC 13.3.0, each as a side effect — <iostream>, <cstdio>, <cstddef>, <vector>, <list>, <string>, <algorithm>, <utility>, <memory>, and the wider set listed in this guide do not.
  • 'deque' is not a member of 'std' means the <deque> include is missing; GCC's note names the header directly: 'std::deque' is defined in header '<deque>'; did you forget to '#include <deque>'? Follow the note. The wording is the same with <iostream> present as with <cstdio> — this type has no second, forward-declaration wording on this toolchain.
  • The expected primary-expression before 'int' and 'd' was not declared in this scope errors that follow are knock-on effects of the missing definition, not separate defects.
  • std::queue and std::stack both default their underlying container to std::deque<T>, which is why their headers rescue a std::deque program — and why that rescue is a side effect to know about, not an include to rely on.
  • 'deque' was not declared in this scope for an unqualified deque(...) use is a different defect: qualify the name as std::deque — the include alone does not bring the name out of namespace std.

The fixes, ranked

  • First, check the include list of the file that names std::deque. If <deque> is not there, add it — that is the fix in the common case, and it is the fix GCC's own note names.
  • Second, do not chase the follow-on errors. Fix the include and recompile; the parse error and the undeclared-d error are consequences, not causes.
  • Third, if the program currently compiles only because it includes <queue>, <stack>, or <regex>, add <deque> anyway — the file names std::deque, and the side-effect definition is not guaranteed to survive a library change.
  • Fourth, if the error says was not declared in this scope instead, fix the name's qualifier to std::deque as well.

Which fix for which cause

  • #include <deque> missing, std::deque used with no includes, <cstdio>, <cstddef>, or <iostream> present: the message is 'deque' is not a member of 'std' with a note naming <deque> — add #include <deque>.
  • #include <deque> missing, but the file includes <queue>, <stack>, or <regex>: the program compiles on GCC 13.3.0 as a side effect — add #include <deque> anyway, because no header is required to provide the definition on <deque>'s behalf.
  • deque(...) used without the std:: qualifier: the message is 'deque' was not declared in this scope — qualify the name as std::deque and include <deque>.

Checklist

  • Check the include list of the file that names the deque, not just the project. The include must be in that file, or in a header that file includes directly by design.
  • Read the error's exact wording before fixing. 'deque' is not a member of 'std' is the missing include; 'deque' was not declared in this scope is the missing qualifier.
  • When the note appears, take the fix from it. For this error GCC names the header — 'std::deque' is defined in header '<deque>' — so follow the note instead of guessing.
  • Do not rely on a neighboring header pulling std::deque in. <vector>, <list>, <string>, <algorithm>, <utility>, and <memory> leave the error in place on this toolchain, and while <queue>, <stack>, and <regex> happen to compile the program, no header is required to define std::deque for you.
  • If the deque holds std::string values, that name comes from <string> — one header per name the file uses, even when a program happens to compile without it.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 2 and 1 for two pushes and the front value, and 1, 3, 10, 30, 20, 30, 20, 20, 1, and 1 across the empty, push, front, back, index, and pop sequence.
  • If elements only ever leave from the front in arrival order, a plain std::deque may be more machinery than the job needs — that is the std::queue adaptor case, in the <queue> header, read with front and removed with pop.

Sources

  • cppreference, std::deque — for std::deque being an indexed sequence container (a double-ended queue) that allows fast insertion and deletion at both its beginning and its end, its elements not being stored contiguously, random access and insertion or removal at either end being constant-time while insertion or removal in the middle is linear, and at, operator[], front, and back being its element-access members, empty and size its capacity members, and push_front, push_back, pop_front, and pop_back among its modifiers.
  • cppreference, Standard library header <deque> — for <deque> being part of the containers library and declaring the std::deque class template (the double-ended queue), the comparison operators and the std::swap specialization for deques, and the C++20 erase and erase_if functions.
  • cppreference, std::queue — for std::queue being a container adaptor whose underlying container defaults to std::deque<T>, the container being required to provide back, front, push_back, and pop_front with their usual semantics, and std::deque and std::list satisfying those requirements.

Keep Exploring