[FIXED] error: 'vector' is not a member of 'std'
Do not miss this exclusive book on Binary Tree Problems. Get it now for free.
In this article, we have explored the compilation error "'vector' is not a member of 'std'" and presented the fix to resolve it.
Table of contents:
- Error: 'vector' is not a member of 'std'
- Fix
Error: 'vector' is not a member of 'std'
If you run the following C++ code, you will get the following error:
#include <iostream>
int main() {
std::vector<float> vector1(100);
return 0;
}
Compilation error:
./code.cpp: In function 'int main()':
./code.cpp:4:2: error: 'vector' is not a member of 'std'
std::vector<float> vector1(100);
^
./code.cpp:4:14: error: expected primary-expression before 'float'
std::vector<float> vector1(100);
^
The compilation error indicates that the compiler is not able to locate vector data type and was searching in the std namespace.
Fix
The fix is to include the vector header file in C++ as follows:
#include <vector>
Following is the complete C++ working code:
#include <iostream>
#include <vector>
int main() {
std::vector<float> vector1(100);
return 0;
}
With the fix in this article at OpenGenus, you must have fixed the error. Continue with C++ development.
Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.