[英]How to include a header file in Visual Studio?
I have a problem in VS2012, where I want to include a header file: 我在VS2012中遇到问题,我想在其中包含头文件:
#include <FileReader>
The problem is that I want to read a file and store it into a matrix. 问题是我想读取文件并将其存储到矩阵中。 However, the include directive fails so that I am unable to read it: 但是,include指令失败,因此我无法阅读它:
#include <mpi.h>
#include <iostream>
#include <FileReader>
int main(int argc, char* argv[])
{
int rows, cols;
float a[10];
//std::vector<float> vec;
FileReader fr("./SampleData.txt");
fr.getSize(rows, cols);
fr.getVector(a);
for (int i = 0; i < cols; i++)
fr.getNextRow(a);
int i;
std::cin >> i;
return 0;
};
Could you please explain why this program does not compile? 您能否解释为什么该程序无法编译?
The answer depends on what FileReader
refers to. 答案取决于FileReader
指的是什么。
Assuming that it refers to a header file for a class you designed yourself: 假设它引用了您自己设计的类的头文件:
FileReader.h
, as names without extension are by convention reserved to the compiler libraries; 您应该将此头文件重命名为FileReader.h
,因为按惯例,不带扩展名的名称保留给编译器库; boost
...) 然后,您应该将标头文件名放在双引号之间,而不是用尖括号括起来,因为尖括号将用于编译器库,或者可能用于项目中使用的第三方库( boost
...) Thus, once FileReader
is renamed into FileReader.h
, the include directive should looks as shown below: 因此,一旦将FileReader
重命名为FileReader.h
,则include指令应如下所示:
`#include "FileReader.h"`
UPDATE 更新
The additional errors you encounter are *linker errors'. 您遇到的其他错误是*“链接器错误”。 They mean that: 他们的意思是:
FileReader.h
but no compiled code can be found for these methods. 但是,某些方法在FileReader.h
中声明,但是找不到这些方法的编译代码。 The most likely explanation is that the source code for these methods is not included in the project. 最可能的解释是这些方法的源代码未包含在项目中。 Thus, you must add this source code to your VS project. 因此,您必须将此源代码添加到VS项目中。 It is probably a file named FileReader.c
or FileReader.cpp
. 它可能是一个名为FileReader.c
或FileReader.cpp
的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.