rKarthik

The question might sound dilly but couldnt find a proper answer.

I created a new project in VC++ 6.0 and included an existing header file into it but when I try to use it in a cpp file (also in the same project), I still have to include the header file specifying its exact location.

I thought if i add the header file to the project, i can just write

# include "xxx.h"

in my cpp file and the header file would be automatically found. Instead I am having to write the path of the header file in the include.

Am I missing something

Thanks,

KarthikR




Re: Visual C++ General Question on including header files to project in VC++

Prasad Somwanshi

If the file you mentioned(header) is in same folder as cpp you want to include this header in, then # include "xxx.h" will work.

xxx.h must be present in one of folders mentioned in Tools-->options-->Directories-->Includes Files to line mentioned by you.





Re: Visual C++ General Question on including header files to project in VC++

rKarthik

Thanks Prasad,

In that case, is there any benefit of adding the header file to the project at all. I can do what you have suggested even without actually adding the header file to the project right

Thanks,

KarthikR






Re: Visual C++ General Question on including header files to project in VC++

Prasad Somwanshi

You can mention directories there, not files.



Re: Visual C++ General Question on including header files to project in VC++

rKarthik

Thanks for your prompt reply Prasad but I am sorry I still don't get it.

Is there any advantage of adding a header file to the project using "Add files to Project" option.

I can add include directories etc to the Project and it works fine but if I just add the header file to the project and dont add its path to the include directories , it doesnt work.

So, I am just trying to understand the implication/purpose of adding a header file to a project.

Thanks,

KarthikR






Re: Visual C++ General Question on including header files to project in VC++

Prasad Somwanshi

Is there any advantage of adding a header file to the project using "Add files to Project" option

No.

Its only its location that matter to cpp file which includes it.





Re: Visual C++ General Question on including header files to project in VC++

rKarthik

Thanks Prasad.

So from what you have mentioned, there is no use or purpose for adding a header file to a project.

Thanks a lot.

KarthikR






Re: Visual C++ General Question on including header files to project in VC++

aao123

1.in standard C++ header file designated "bla.h" - means header files in the current directory for the file that includes it. MS hacked it so it also works with files in the include path.

2.in standard C++ header file designated <bla.h> - means header file is somewhere in the include path

3. Including header file in you project is useful for at least 2 reasons

a. it helps compiler/make to identify this header file as dependency. Microsoft build system is pretty good at guessing, but not 100%

b. If you do not include header file autocomplete and definition lookup (f12) might not work.

first two items is useful if you want to write clean code. 3rd is very useful at maintenance time. I feel real bad for MS C++ team when I see MS wizard generated code like :

#include ".\myclass.h"

whoever wrote that wizard did not have a clue.





Re: Visual C++ General Question on including header files to project in VC++

rKarthik

It would have been nice if VC++ IDE could automatically add a header file to the include path, if it is added to the project. In that case, you could just add the header file to the project and refer to it in a cpp file as

#include "xxx.h" or #include<x.h> without manually having to add it to the include path.

If someone really doesnt want to add the header file to the project but still wants to include it, he could still manually add the location of the file in the include path.

Thanks,

KarthikR