Reputation:
I want to write two program(.h and .cpp) with below code and use .h file in .cpp but when i run it in TC occur below error
.h File
#ifndef ADD_H
#define ADD_H
int add(int x, int y)
{
return x + y;
}
#endif
.cpp file
#include <iostream.h>
#include <conio.h>
#include "Add.h"
void main()
{
clrscr();
cout << "Sum of 3 and 4 :" << add(3, 4);
getch();
}
Error
Unable to open include file "Add.h"
Upvotes: 1
Views: 237
Reputation: 11797
Add.h is not in the includes path of your compiler.
By the way, iostream.h
is deprecated, you should include iostream
. Also, cout
is in the std
namespace, so you need a using namespace std;
in your .cpp file or, alternatively, use std::cout
instead of cout
.
Upvotes: 0
Reputation: 882716
There's a few things you should look into:
<>
and ""
variants - make sure your header file is in that path somewhere.add.h
(all lowercase).clrscr
and getch
), there's really no excuse not to upgrade to a more modern environment.Upvotes: 2
Reputation: 84239
You probably just need to add -I.
flag to you compile line.
Upvotes: 0