'std::queue' Is Not a Member of 'std' Fix
Written November 27, 2026 · Tested with GCC 13.3.0 · 14 min read
- The error: the include is missing
- The same missing include through <iostream>: the same wording
- The fix
- First in, first out: push, pop, front, back, size, and empty
Written November 27, 2026
Tested with GCC 13.3.0
What this guide is
std::queue is a class template defined in the header <queue>. It is a container adaptor that gives the functionality of a queue — specifically, a first-in, first-out (FIFO) data structure. The class template acts as a wrapper to an underlying container: only a specific set of functions is provided, the queue pushes elements on the back of the underlying container, and it pops them from the front.
Because the class template lives in one specific header, a missing #include <queue> is the cause behind this error, and for this type GCC words it one way: 'queue' is not a member of 'std', with a note that names the header — 'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'? That wording is reproduced below, exactly as GCC 13.3.0 prints it. The fix is to add <queue>.
The error: the include is missing
This program declares a std::queue, pushes two values onto it, and prints its size, but includes only <cstdio>:
#include <cstdio>
int main() {
std::queue<int> q;
q.push(1);
q.push(2);
std::printf("%zu\n", q.size());
return 0;
}
$ g++ -std=c++17 cstdio.cpp -o cstdio_prog
cstdio.cpp: In function 'int main()':
cstdio.cpp:3:10: error: 'queue' is not a member of 'std'
3 | std::queue<int> q;
| ^~~~~
cstdio.cpp:2:1: note: 'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
1 | #include <cstdio>
+++ |+#include <queue>
2 | int main() {
cstdio.cpp:3:16: error: expected primary-expression before 'int'
3 | std::queue<int> q;
| ^~~
cstdio.cpp:4:5: error: 'q' was not declared in this scope
4 | q.push(1);
| ^
The two errors after the note are knock-on effects of the first one: because the declaration of std::queue was never seen, the compiler cannot parse the declaration of q, and the later use of q 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::queue print their results, so <iostream> is usually already included. For some types that changes the wording of the missing-include error; for std::queue it does not. This is the same program with <iostream> and std::cout instead of <cstdio> and std::printf:
#include <iostream>
int main() {
std::queue<int> q;
q.push(1);
q.push(2);
std::cout << q.size() << "\n";
return 0;
}
$ g++ -std=c++17 iostream.cpp -o iostream_prog
iostream.cpp: In function 'int main()':
iostream.cpp:3:10: error: 'queue' is not a member of 'std'
3 | std::queue<int> q;
| ^~~~~
iostream.cpp:2:1: note: 'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
1 | #include <iostream>
+++ |+#include <queue>
2 | int main() {
iostream.cpp:3:16: error: expected primary-expression before 'int'
3 | std::queue<int> q;
| ^~~
iostream.cpp:4:5: error: 'q' was not declared in this scope
4 | q.push(1);
| ^
The error and the note are identical to the <cstdio> shape: no header in <iostream>'s include chain declares std::queue 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 do not rescue the program either. Every one of them fails with the same 'queue' is not a member of 'std' error and the same note naming <queue>:
- With only
<vector>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<cstdio>and<vector>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<iostream>and<vector>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With only
<deque>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<cstdio>and<deque>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<iostream>and<deque>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With only
<list>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<cstdio>and<list>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<iostream>and<list>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With only
<stack>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<cstdio>and<stack>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<iostream>and<stack>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With only
<string>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<cstdio>and<string>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<iostream>and<string>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With only
<algorithm>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<cstdio>and<algorithm>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<iostream>and<algorithm>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With only
<utility>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<cstdio>and<utility>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<iostream>and<utility>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With only
<memory>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<cstdio>and<memory>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>. - With
<iostream>and<memory>included, the program fails with'queue' is not a member of 'std'and the note naming<queue>.
Two of those are worth pausing on. <deque> is the header for the container std::queue wraps by default, and <stack> is the header for the sibling container adaptor — and neither defines std::queue. 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>, <regex>, <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: none of them rescues this program. No standard header is required to define std::queue on behalf of <queue>, and a program that compiled only because some other header happened to pull the definition in as a side effect could break under a different library version. Include <queue> in every file that names std::queue.
The fix
Add the header:
#include <iostream>
#include <queue>
int main() {
std::queue<int> q;
q.push(1);
q.push(2);
std::cout << q.size() << "\n";
std::cout << q.front() << "\n";
return 0;
}
$ 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 oldest value, the one pop would remove — prints 1. One include, <queue>, defines the class template.
First in, first out: push, pop, front, back, size, and empty
A queue serves its elements in the order they arrived. push inserts an element at the end, pop removes the first element, front accesses the first element, back accesses the last element, size returns the number of elements, and empty checks whether the adaptor is empty:
#include <iostream>
#include <queue>
int main() {
std::queue<int> q;
std::cout << q.empty() << "\n";
q.push(10);
q.push(20);
q.push(30);
std::cout << q.size() << "\n";
std::cout << q.front() << "\n";
std::cout << q.back() << "\n";
q.pop();
std::cout << q.front() << "\n";
std::cout << q.size() << "\n";
q.pop();
q.pop();
std::cout << q.empty() << "\n";
return 0;
}
$ g++ -std=c++17 behavior.cpp -o behavior_prog
$ ./behavior_prog
1
3
10
30
20
2
1
The queue starts empty, so the first empty prints 1. After three pushes size prints 3, front prints 10 — the first value pushed — and back prints 30, the last one. pop removes the front element and returns nothing, so the next front prints 20 and size prints 2. Two more pops drain the queue, and the final empty prints 1 again. Note the order: 10 leaves before 20, and 20 before 30 — first in, first out, the opposite of a stack's last-in, first-out order.
The container underneath: std::deque by default, std::list on request
std::queue does not store its elements itself: it is an adaptor wrapped around an underlying container, held as its protected member c, and every operation forwards to that container — push is the container's push_back, pop is its pop_front, and front and back are its front and back. The underlying container defaults to std::deque<T>, so std::queue<int> is std::queue<int, std::deque<int>>. The container must provide back, front, push_back, and pop_front with their usual semantics, and the standard containers std::deque and std::list satisfy those requirements — so a std::list can be named as the second template argument when its storage is what the program wants:
#include <iostream>
#include <list>
#include <queue>
int main() {
std::queue<int, std::list<int>> q;
q.push(1);
q.push(2);
std::cout << q.size() << "\n";
std::cout << q.front() << "\n";
std::cout << q.back() << "\n";
return 0;
}
$ g++ -std=c++17 list_container.cpp -o list_container_prog
$ ./list_container_prog
2
1
2
The list-backed queue behaves exactly like the default one for these operations: size prints 2, front prints 1, and back prints 2. Either way, the adaptor's own name still comes from <queue> — including <deque> or <list> gives the file the container, not the adaptor, which is why neither header rescued the failing programs above.
The neighboring error: std::priority_queue, same header, same failure
std::priority_queue is the other class template defined in the same header <queue>: a container adaptor that provides constant time lookup of the largest (by default) element, at the expense of logarithmic insertion and extraction. Leave <queue> out and it fails the same way, with its own name in the error and the same header in the note:
#include <cstdio>
int main() {
std::priority_queue<int> pq;
pq.push(1);
std::printf("%zu\n", pq.size());
return 0;
}
$ g++ -std=c++17 pq_missing.cpp -o pq_missing_prog
pq_missing.cpp: In function 'int main()':
pq_missing.cpp:3:10: error: 'priority_queue' is not a member of 'std'
3 | std::priority_queue<int> pq;
| ^~~~~~~~~~~~~~
pq_missing.cpp:2:1: note: 'std::priority_queue' is defined in header '<queue>'; did you forget to '#include <queue>'?
1 | #include <cstdio>
+++ |+#include <queue>
2 | int main() {
pq_missing.cpp:3:25: error: expected primary-expression before 'int'
3 | std::priority_queue<int> pq;
| ^~~
pq_missing.cpp:4:5: error: 'pq' was not declared in this scope
4 | pq.push(1);
| ^~
The same added include fixes it, and the fixed program shows the difference from a plain queue: elements come out by priority, not by arrival order. top accesses the top element, and pop removes the top element:
#include <iostream>
#include <queue>
int main() {
std::priority_queue<int> pq;
pq.push(1);
pq.push(3);
pq.push(2);
std::cout << pq.top() << "\n";
pq.pop();
std::cout << pq.top() << "\n";
std::cout << pq.size() << "\n";
return 0;
}
$ g++ -std=c++17 pq_good.cpp -o pq_good_prog
$ ./pq_good_prog
3
2
2
The values went in as 1, 3, 2, but top prints 3 — the largest — and after pop removes it, top prints 2, with size at 2. If the error names priority_queue instead of queue, nothing else changes: the note still names <queue>, and that one include defines both adaptors.
A different wording: queue without the std::
Calling the class without its namespace qualifier is a different defect, and GCC words it differently:
#include <iostream>
#include <queue>
int main() {
queue<int> q;
q.push(1);
std::cout << q.size() << "\n";
return 0;
}
$ g++ -std=c++17 unqualified.cpp -o unqualified_prog
unqualified.cpp: In function 'int main()':
unqualified.cpp:4:5: error: 'queue' was not declared in this scope; did you mean 'std::queue'?
4 | queue<int> q;
| ^~~~~
| std::queue
In file included from /usr/include/c++/13/queue:66,
from unqualified.cpp:2:
/usr/include/c++/13/bits/stl_queue.h:96:11: note: 'std::queue' declared here
96 | class queue
| ^~~~~
unqualified.cpp:4:11: error: expected primary-expression before 'int'
4 | queue<int> q;
| ^~~
unqualified.cpp:5:5: error: 'q' was not declared in this scope
5 | q.push(1);
| ^
'queue' 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 <queue>, so the include is not the problem — the declaration it adds is std::queue, inside namespace std, and the use must be qualified as std::queue, or the file must bring the name in deliberately. GCC's error carries the suggestion inline — did you mean 'std::queue'? — and its note points at the declaration itself, reached through the <queue> header. 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::queueis defined by#include <queue>; no other header is required to define it. None of the headers probed for this guide —<iostream>,<cstdio>,<cstddef>,<vector>,<deque>,<list>,<stack>,<string>,<algorithm>,<utility>,<memory>, or any of the wider set listed in this guide — definesstd::queueon GCC 13.3.0.'queue' is not a member of 'std'means the<queue>include is missing; GCC's note names the header directly:'std::queue' is defined in header '<queue>'; did you forget to '#include <queue>'?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'q' was not declared in this scopeerrors that follow are knock-on effects of the missing definition, not separate defects. std::priority_queueis declared by the same#include <queue>: its missing-include error is'priority_queue' is not a member of 'std'with the note naming<queue>— the same fix.'queue' was not declared in this scopefor an unqualifiedqueue(...)use is a different defect: qualify the name asstd::queue— the include alone does not bring the name out of namespacestd.
The fixes, ranked
- First, check the include list of the file that names
std::queue. If<queue>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-
qerror are consequences, not causes. - Third, if the failing name is
std::priority_queue, the same include is the fix — both adaptors live in<queue>, so one line covers both. - Fourth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::queueas well.
Which fix for which cause
#include <queue>missing,std::queueused with no includes,<cstdio>,<cstddef>, or<iostream>present: the message is'queue' is not a member of 'std'with a note naming<queue>— add#include <queue>.#include <queue>missing,std::priority_queueused: the message is'priority_queue' is not a member of 'std'with a note naming<queue>— add#include <queue>.queue(...)used without thestd::qualifier: the message is'queue' was not declared in this scope— qualify the name asstd::queueand include<queue>.
Checklist
- Check the include list of the file that names the queue, 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.
'queue' is not a member of 'std'is the missing include;'queue' was not declared in this scopeis the missing qualifier. - When the note appears, take the fix from it. For this error GCC names the header —
'std::queue' is defined in header '<queue>'— so follow the note instead of guessing. - Do not rely on a neighboring header pulling
std::queuein. None of<iostream>,<cstdio>,<cstddef>,<vector>,<deque>,<list>,<stack>,<string>,<algorithm>,<utility>, or<memory>defines it on this toolchain, and no header is required to. Even<deque>— the container the adaptor wraps by default — and<stack>, the sibling adaptor's header, leave the error in place. - If the queue holds
std::stringvalues, 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
2and1for two pushes and the front value, and1,3,10,30,20,2, and1across the empty, size, front, back, and pop sequence. - If elements must come out largest first rather than in arrival order,
std::queueis the wrong adaptor — that is thestd::priority_queuecase, in the same<queue>header, read withtopinstead offront.
Related guides
- 'std::vector' Is Not a Member of 'std' Fix — the same missing-include shape for the run-time-sized sequence container in
<vector>, with the same note naming the header. - 'std::set' Is Not a Member of 'std' Fix — the same missing-include shape for the sorted unique-value container in
<set>, with the same note naming the header. - C++ STL Containers: vector, map, and set by Example — the wider tour of the containers this adaptor belongs with, including
std::vectorandstd::set.
Sources
- cppreference,
std::queue— forstd::queuebeing a container adaptor that gives the functionality of a FIFO queue, acting as a wrapper to the underlying container that pushes elements on its back and pops them from its front, the underlying container defaulting tostd::deque<T>and required to provideback,front,push_back, andpop_front(requirementsstd::dequeandstd::listsatisfy), andfront,back,empty,size,push, andpopbeing its element-access, capacity, and modifier members. - cppreference, Standard library header
<queue>— for<queue>declaring thestd::queueandstd::priority_queueclass templates, withstd::queuedefaulting its container todeque<T>andstd::priority_queuedefaulting its container tovector<T>with alesscomparison. - cppreference,
std::priority_queue— forstd::priority_queuebeing a container adaptor that provides constant time lookup of the largest (by default) element at the expense of logarithmic insertion and extraction, andtop,empty,size,push, andpopbeing its element-access, capacity, and modifier members.
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.