×

Search anything:

[FIXED] error: 'vector' is not a member of 'std'

C++

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

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:

  1. Error: 'vector' is not a member of 'std'
  2. 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.

Geoffrey Ziskovin

Geoffrey Ziskovin

Geoffrey Ziskovin is an American Software Developer and Author with an experience of over 30 years. He started his career with Haskell and has interviewed over 700 candidates for Fortune 500 companies

Read More

Improved & Reviewed by:


OpenGenus Tech Review Team OpenGenus Tech Review Team
[FIXED] error: 'vector' is not a member of 'std'
Share this