Problem in Include file
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"
开发者_Python百科void main()
{
clrscr();
cout << "Sum of 3 and 4 :" << add(3, 4);
getch();
}
Error
Unable to open include file "Add.h"
There's a few things you should look into:
- the location (search path) of header files is implementation dependent, both for the
<>
and""
variants - make sure your header file is in that path somewhere. - you may find that you need to use
add.h
(all lowercase). - you shouldn't generally include code in header files (you should put it in a separate C file and just use the header file to list declarations (or the prototype in your case).
- if that's Turbo C you're using (and it probably is, given the
clrscr
andgetch
), there's really no excuse not to upgrade to a more modern environment.
You probably just need to add -I.
flag to you compile line.
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
.
精彩评论