我有main.cpp
和add.cpp
add.h
文件
当我尝试包含add.h
时,我得到以下编译错误
main.cpp:2:10: fatal error: add.h: No such file or directory
2 | #include <add.h>
| ^~~~~~~
compilation terminated.
代码如下:
main.cpp
#include <iostream>
#include <add.h>
using namespace std;
int main()
{
cout << "The sum of 3 and 4 is " << add(3, 4) << endl;
return 0;
}
add.cpp
int add(int x, int y)
{
return x + y;
};
add.h
int add(int x, int y);
#include <add.h>
导致编译器在系统包含目录中搜索文件add.h
,而不是当前目录。如果您想包含当前目录中的文件add.h
,请使用:
#include "add.h"