C++
'std::string_view' Is Not a Member of 'std' Fix
std::string_view lives in one header,
Written November 29, 2026 · Tested with GCC 13.3.0 · 14 min read
- The rule underneath: one header, C++17 or later
- The first failure: no <stringview> include
- The second failure: <stringview> included, compiled as C++14
- 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::string_view name means the compiler has no string_view name inside std to find. Inside a function, GCC words it exactly as this guide's title promises: 'string_view' is not a member of 'std'. The common cause is a missing include: nothing in the file included <string_view>, the header that declares the name, so the lookup fails at the first use. The second cause is the language mode: std::string_view is since C++17, so a file compiled in an older mode gets no std::string_view either - and that shape keeps the same not-a-member error, telling the two shapes apart only by the note attached to it.
The wording also changes with where the failing name sits. At namespace scope, where the name is used as a type for a variable declaration, GCC reports 'string_view' in namespace 'std' does not name a type instead. Both wordings appear below; they are one fault - the name is absent - read at two different positions in the file.
Between the two causes sits a trap this guide also covers: some other headers pull the string_view declarations in as a side effect. A program that uses std::string_view without including <string_view> can compile anyway when <string> or <iostream> is present, and fail the day either include is removed. The fix is never the lucky header - it is #include <string_view> in the file itself, plus a language mode of C++17 or later.
The rule underneath: one header, C++17 or later
The std::basic_string_view page dates the type: the class template basic_string_view is since C++17, describing an object that can refer to a constant contiguous sequence of characters, and the typedefs table gives std::string_view as std::basic_string_view<char>, also C++17, defined in header <string_view>. There is no C++14 form of std::string_view: the type arrived with the 2017 standard.
The basic_string_view class template, the typedef names string_view, wstring_view, u16string_view and u32string_view (plus u8string_view since C++20), hash support for the views, and the comparison and stream-output operators, all in namespace std. The member list on the basic_string_view page shows the operations a view actually offers: size, find, substr and the constant npos for searching and slicing, and only remove_prefix, remove_suffix and swap as modifiers - a view refers to characters it does not own, so it has no operation that appends to them. The std::basic_string_view::substr page gives the slicing member this guide's fix uses the same date: substr since C++17, returning a view of the substring starting at a position, with a length that is the smaller of the count requested and what remains. So a std::string_view name needs both conditions at once: the header included, so the declaration is in the file, and a language mode of C++17 or later, so the header is allowed to declare it.
The first failure: no <string_view> include
This program uses std::string_view and includes no header at all - deliberately, because the obvious companion header for printing, <iostream>, turns out to rescue this name, as the sweep below shows, and would hide the failure:
int main() {
std::string_view sv = "hello world";
return sv.size() == 11 ? 0 : 1;
}
$ 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:2:10: error: 'string_view' is not a member of 'std'
2 | std::string_view sv = "hello world";
| ^~~~~~~~~~~
p1_fail_no_include.cpp:1:1: note: 'std::string_view' is defined in header '<string_view>'; did you forget to '#include <string_view>'?
+++ |+#include <string_view>
1 | int main() {
p1_fail_no_include.cpp:3:12: error: 'sv' was not declared in this scope
3 | return sv.size() == 11 ? 0 : 1;
| ^~
Read the error's subject: it names string_view as not a member of std, and the note underneath names the remedy exactly - the type is defined in header <string_view>, and the include is missing. The language mode here is already C++17, so the mode is not the problem in this shape; the missing header is. The second error, 'sv' was not declared in this scope, is fallout: the declaration failed, so the variable does not exist on the next line.
The same missing include at namespace scope is worded differently. This program declares the view as a file-scope variable, still with no header:
std::string_view g_sv = "hello";
int main() {
return g_sv.size() == 5 ? 0 : 1;
}
$ g++ -std=c++17 p1b_fail_scope.cpp -o p1b_fail_scope
p1b_fail_scope.cpp:1:6: error: 'string_view' in namespace 'std' does not name a type
1 | std::string_view g_sv = "hello";
| ^~~~~~~~~~~
p1b_fail_scope.cpp:1:1: note: 'std::string_view' is defined in header '<string_view>'; did you forget to '#include <string_view>'?
+++ |+#include <string_view>
1 | std::string_view g_sv = "hello";
p1b_fail_scope.cpp: In function 'int main()':
p1b_fail_scope.cpp:4:12: error: 'g_sv' was not declared in this scope
4 | return g_sv.size() == 5 ? 0 : 1;
| ^~~~
Same fault, same missing-header note, different first line: where the name is used as a type outside a function, GCC says it does not name a type; where it is used inside a function, GCC says it is not a member of std. Recognize either wording as the missing-include shape when the note points at <string_view>.
The second failure: <string_view> included, compiled as C++14
The same use of the view with the header included still fails when the language mode is older than the type - and here the diagnostic is the title error again, not a refusal from inside the header:
#include <string_view>
#include <iostream>
int main() {
std::string_view sv = "hello world";
std::cout << sv.size() << "\n";
return 0;
}
$ g++ -std=c++14 p2_included.cpp -o p2_cpp14
p2_included.cpp: In function 'int main()':
p2_included.cpp:5:10: error: 'string_view' is not a member of 'std'
5 | std::string_view sv = "hello world";
| ^~~~~~~~~~~
p2_included.cpp:5:10: note: 'std::string_view' is only available from C++17 onwards
p2_included.cpp:6:18: error: 'sv' was not declared in this scope
6 | std::cout << sv.size() << "\n";
| ^~
The first line matches the missing-include shape exactly, which is what makes this shape easy to misread: the include is present and correct, and adding it again changes nothing. The tell is the note - 'std::string_view' is only available from C++17 onwards - which replaces the missing-header note from the first shape. At -std=c++98 this exact program fails with the same first error and the same note, word for word: GCC's <string_view> does not stop with a #error of its own in either older mode, so the not-a-member error is all there is to read, and the note is the whole diagnosis. Raise the mode and the same file compiles unchanged - at -std=c++17 it compiles and prints 11.
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::string_view the sweep splits, and the split is the point. Each sweep program uses the view with one candidate header as its only include, and no other header - a second include would be its own possible rescue and would spoil the measurement. This program, with <string> in that position and still no <string_view>, compiles and runs:
#include <string>
int main() {
std::string_view sv = "hello world";
return sv.size() == 11 ? 0 : 1;
}
$ g++ -std=c++17 sweep_string.cpp -o sweep_string
$ ./sweep_string
The run prints nothing and exits with success, which is the pass signal this program is built on: it returns 0 only when the view's size is 11. <iostream> in the same position also compiles and runs the program - which is why the first failure above had to leave it out. Both headers work with strings and text, and in this standard library they bring the string_view declarations in with them, so the std::string_view name resolves even though <string_view> was never included. That is a property of these particular headers in this library implementation, scoped to the name this program uses - std::string_view itself - not a promise about any other name from the header, 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 candidate header with <vector> fails with the same first error as the missing-include shape:
#include <vector>
int main() {
std::string_view sv = "hello world";
return sv.size() == 11 ? 0 : 1;
}
$ g++ -std=c++17 sweep_vector.cpp -o sweep_vector
sweep_vector.cpp: In function 'int main()':
sweep_vector.cpp:4:10: error: 'string_view' is not a member of 'std'
4 | std::string_view sv = "hello world";
| ^~~~~~~~~~~
sweep_vector.cpp:2:1: note: 'std::string_view' is defined in header '<string_view>'; did you forget to '#include <string_view>'?
1 | #include <vector>
+++ |+#include <string_view>
2 |
sweep_vector.cpp:5:12: error: 'sv' was not declared in this scope
5 | return sv.size() == 11 ? 0 : 1;
| ^~
The same program was compiled with each of <algorithm>, <array> and <utility> as the only candidate header, at C++17: every one fails with the same first error, 'string_view' is not a member of 'std'. So of the six headers probed in place of <string_view>, two - <string> and <iostream> - rescue this program and four do not. Neither outcome changes the repair: include <string_view> directly in every file that names std::string_view, rather than relying on a transitive rescue that the file does not state.
The fix: include <string_view> and compile at C++17 or later
Both halves together - the header included, the mode at C++17 - and the type is fully usable. This program splits a comma-separated view into its parts with find and substr and prints each part with its size:
#include <string_view>
#include <iostream>
int main() {
std::string_view text = "alpha,beta,gamma";
std::size_t start = 0;
while (true) {
std::size_t comma = text.find(',', start);
std::string_view part = text.substr(start, comma - start);
std::cout << part << " " << part.size() << "\n";
if (comma == std::string_view::npos) break;
start = comma + 1;
}
return 0;
}
$ g++ -std=c++17 p4_fix.cpp -o p4_fix
$ ./p4_fix
alpha 5
beta 4
gamma 5
Every name that failed before now resolves: find locates each comma, or returns std::string_view::npos when none remains, and substr returns the view between the current start and that comma - the pieces the basic_string_view page lists, assembled into the split. No part is copied or modified: each part is a view into text, reporting its characters through the stream operator and its length through size(), which is the whole job a view exists for. The output is fully determined by the input text - the three parts and their lengths are fixed - so any other output means the program, not the machine, differs.
Neighboring error: a member string_view does not have
Once <string_view> is included and the mode is right, a wrong member name produces a different error on a different subject. A view is read-only: its only modifiers shrink the view itself, so it has no push_back, and asking for it fails like this:
#include <string_view>
#include <iostream>
int main() {
std::string_view sv = "hello";
sv.push_back('!');
std::cout << sv.size() << "\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:6:8: error: 'using std::string_view = class std::basic_string_view<char>' {aka 'class std::basic_string_view<char>'} has no member named 'push_back'
6 | sv.push_back('!');
| ^~~~~~~~~
The contrast separates the two errors cleanly. This error names the class - std::basic_string_view<char>, spelled out through the string_view typedef - and the missing member, which proves the type was found: the include and the mode are already right, and only the member name is wrong, because the operation itself does not exist on a view. The title error names string_view as not a member of std, because the type was never there to be used. The repair here is not another member: to build a longer string, own the characters - put them in a std::string and append to that, and take a view of the result when a view is what the next step needs.
Neighboring error: a view is not a std::string
The other neighboring fault treats the view as the owning string it points into. A std::string_view does not convert to a std::string by assignment, so initializing one from the other fails at the initialization:
#include <string_view>
#include <string>
#include <iostream>
int main() {
std::string_view sv = "hello";
std::string s = sv;
std::cout << s << "\n";
return 0;
}
$ g++ -std=c++17 p6_neighbour_assign_string.cpp -o p6_neighbour_assign_string
p6_neighbour_assign_string.cpp: In function 'int main()':
p6_neighbour_assign_string.cpp:7:21: error: conversion from 'std::string_view' {aka 'std::basic_string_view<char>'} to non-scalar type 'std::string' {aka 'std::__cxx11::basic_string<char>'} requested
7 | std::string s = sv;
| ^~
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: the conversion from a view to an owning string is a construction, not an assignment, and it is spelled with the view's own accessors - std::string s(sv.data(), sv.size()) builds the string from exactly the characters the view covers, including any the view holds past a null character that a plain pointer conversion would stop at. When an error names complete std::string_view and std::string 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
'string_view' is not a member of 'std'and the note under it says the type is defined in header<string_view>and asks whether the include was forgotten: the header is missing - add#include <string_view>; every later error in the cascade traces to the absent name. - The first error is
'string_view' in namespace 'std' does not name a type: the same missing include, read at namespace scope where the name is used as a type - add<string_view>the same way. - The first error is
'string_view' is not a member of 'std'but the note under it saysstd::string_viewis only available from C++17 onwards, and the file already includes<string_view>: the language mode is older than C++17 - the compile line shows-std=c++14,-std=c++98or an equivalent setting; compile at-std=c++17or later instead of changing code. This shape appears at both probed older modes with identical wording. - The program compiles without
<string_view>because another header is pulling the declarations in -<string>or<iostream>in the sweep above, and other headers can do the same: that is a transitive rescue, scoped to the names used - add<string_view>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>,<algorithm>,<array>or<utility>: none of them declaresstd::string_view; the probed sweep found no rescue from any of the four, so add<string_view>itself. - The error instead names the class, as in
has no member named 'push_back'onstd::basic_string_view<char>: the type was found and the member does not exist on a view - a view cannot append; build the text in astd::stringinstead. - The error is a conversion failure naming
std::string_viewon one side andstd::stringon the other: a view was assigned where an owning string belongs - construct it explicitly from the view'sdata()andsize().
Checklist
- The file includes
<string_view>itself - not a neighboring header in its place, and not a transitive rescue through another header such as<string>or<iostream>- before anystd::string_viewname is used. - The compile line, or the build system's language standard setting, is C++17 or later; a pre-C++17 mode keeps the same not-a-member error and adds the note that the type is only available from C++17 onwards.
- The note under the first error is read, not just the error: a defined-in-header note means the include is missing, an only-available-from-C++17 note means the mode is too old - the error line alone cannot tell the two shapes apart.
- The first error is read before the cascade: the
'was not declared in this scope'errors about the variable that failed to declare disappear when the name error at the top is fixed. - A view is treated as read-only: no member that appends or edits characters is expected of it, and text that must grow is built in a
std::stringfirst. - A
std::stringwanted from a view is constructed from the view'sdata()andsize(), never assigned from the view directly. - The fixed program compiles at C++17, runs, and prints the three parts of the split -
alpha 5,beta 4,gamma 5- in order.
Related guides
- 'std::filesystem' Is Not a Member of 'std' Fix - the same missing-name fault on the filesystem library:
std::filesystemis declared by<filesystem>, and because that library is also C++17, it fails in both shapes covered here - missing include, and a mode that is too old for it. - 'std::chrono' Is Not a Member of 'std' Fix - the same fault on the chrono library, with one contrast worth seeing side by side: at a pre-C++11 mode its header stops with a
#errorof its own, while<string_view>at a pre-C++17 mode leaves the not-a-member error and its note as the only diagnosis. - 'std::vector' Is Not a Member of 'std' Fix - the same missing-name fault on a container:
std::vectoris declared by<vector>- a header that, in the sweep above, does not return the favor forstd::string_view.
Sources
- cppreference.com, std::basic_string_view — the type at the center of the error: the class template
basic_string_viewsince C++17, an object that can refer to a constant contiguous sequence of characters, withstd::string_viewas itschartypedef, defined in header<string_view>- and a member list whose only modifiers areremove_prefix,remove_suffixandswap, with nopush_back, which is the boundary the neighboring-error section draws. - cppreference.com, Standard library header
(C++17) — what the header declares: thebasic_string_viewclass template, the typedef namesstring_view,wstring_view,u16string_viewandu32string_view(plusu8string_viewsince C++20), hash support for the views, and the comparison and stream-output operators, all in namespacestd- the declarations a file gets only by including<string_view>itself (or, for some names, by a neighbor's transitive include, which the sweep section measures). - cppreference.com, std::basic_string_view::substr — the slicing member the fix program uses:
substrsince C++17, returning a view of the substring starting at a given position, with a length that is the smaller of the count requested andsize() - pos- the operation that turns each comma position found byfindinto the part the fix prints.
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.