C++ 无法打开包含文件:'vector.h':没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6729428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot open include file: 'vector.h': No such file or directory
提问by craftace
At the top of the file, I have:
在文件的顶部,我有:
#include "vector.h"
then I do a:
然后我做一个:
vector<vtarg> targVector;
and got the following error
并得到以下错误
Cannot open include file: 'vector.h': No such file or directory
Am I missing out something? I tried #include "vector" even more errors.
我错过了什么吗?我试过 #include "vector" 甚至更多的错误。
#include "afxwin.h"
#include "vector.h"
// CTargDlg dialog
class CTargDlg : public CDialog {
// Construction
public:
CTargDlg(CWnd* pParent = NULL);
// standard constructor
vector<vtarg> targVector;
回答by Frerich Raabe
You need to use
你需要使用
#include <vector>
instead, without the .hfile extension. Furthermore, the vectortemplate lives in the stdnamespace, so you should define your vector like
相反,没有.h文件扩展名。此外,vector模板位于std命名空间中,因此您应该定义您的向量,例如
std::vector<vtarg> targVector;
Also make sure to include whatever headers are necessary for vtarg.
还要确保包含vtarg.
回答by Patrick
You made 3 errors.
你犯了3个错误。
First, the include file is called vector, not vector.h.
首先,包含文件被称为vector,而不是vector.h。
Second, this vector is an include that's part of the standard C++ run-time library, you need to use the <> include construction, like this:
其次,这个向量是一个包含,它是标准 C++ 运行时库的一部分,你需要使用 <> 包含构造,像这样:
#include <vector>
Third, the vector class (actually templated class) belongs to the std namespace. So you should write:
第三,vector类(实际上是模板化类)属于std命名空间。所以你应该写:
std::vector<vtarg> targVector;
回答by jalf
The header file is called vector, not vector.h.
头文件被称为vector,而不是vector.h.
In general, standard C++ headers do not have the .hsuffix.
通常,标准 C++ 头文件没有.h后缀。
If you get "even more errors" wen you #include <vector>, then you'll need to solve those errors. But since you haven't said what those errors are, it's kind of hard to help you with that.
如果您收到“更多错误” #include <vector>,那么您需要解决这些错误。但是由于您还没有说明这些错误是什么,所以很难帮助您解决这个问题。
回答by Nicol Bolas
There is no "vector.h". The header file for std::vector is <vector>. Indeed, all of the C++ standard library headers (save for the C-compatibility ones) do not have a ".h" at the end of them.
没有"vector.h"。std::vector 的头文件是<vector>. 事实上,所有的 C++ 标准库头文件(除了 C 兼容的)在它们的末尾都没有“.h”。
回答by sAm
try this alternative
试试这个替代方案
include "vector"
some compilers, like visual c++ 2010, support this type of notations.
Also if it is a .c file for example xy.c use include"xy".
一些编译器,如 Visual c++ 2010,支持这种类型的符号。
此外,如果它是 .c 文件,例如 xy.c,请使用 include"xy"。
回答by Oscar Galvan
#include "vector.h"is actually the correct way of using this if you are using the stanford library collection.
#include "vector.h"如果您使用的是斯坦福图书馆馆藏,实际上是正确的使用方法。
https://www.stanford.edu/class/cs106b/cppdoc/Vector-class.html
https://www.stanford.edu/class/cs106b/cppdoc/Vector-class.html
The problem is that I don't think most compilers are set up to include the stanford library so the file is something you're going to have to include yourself I think.
问题是我认为大多数编译器都没有设置为包含 stanford 库,因此我认为该文件是您必须包含自己的内容。

