我想用下面的代码编写两个程序(.h和.cpp)并在.cpp中使用.h文件,但是当我在TC中运行时发生错误
.h文件
#ifndef ADD_H
#define ADD_H
int add(int x, int y)
{
return x + y;
}
#endif
.cpp文件
#include <iostream.h>
#include <conio.h>
#include "Add.h"
void main()
{
clrscr();
cout << "Sum of 3 and 4 :" << add(3, 4);
getch();
}
错误
无法打开包含文件“Add.h”
答案 0 :(得分:2)
您应该考虑以下几点:
<>
和""
变体 - 确保您的头文件位于该路径的某个位置。add.h
(全部小写)。clrscr
和getch
),那么就没有理由不升级到更现代的环境。答案 1 :(得分:0)
您可能只需要在编译行中添加-I.
标志。
答案 2 :(得分:0)
Add.h不在编译器的include路径中。
顺便说一下,iostream.h
已被弃用,您应该包含iostream
。此外,cout
位于std
命名空间中,因此您需要在.cpp文件中使用using namespace std;
,或者使用std::cout
代替cout
。< / p>