Hello , I am new c plus plus student. I read this tutorial and it looks a good one.I will be glad if someone tells me how to create a .cpp and .h files for a program.let suppose for this program.
File > New > File... > Visual C++ > C++ File (.cpp)
-If you want to create a program you should create a project first:
File > New > Project > (The template you want) [I suggest you the "Empty Project"]
Then you can add files:
Project > Add New Item...
The same way you create a cpp:
(to add a header file to a project)
Project > Add New Item... > Header File (.h)
Then you can #include "yourHeader.h" in other files in your project
I am sorry I am very new .what is the difference between header and source file ?
As far as I know , we include headers in the source file and make it workable. Isn't it ?
In the header files you have declarations so you can use function, classes, whatever which are not defined in your source file (they can be defined in another source file you will compile or in a library, for template stuff, you will have the definition in the header)
having the code in multiple source files can be useful for large projects, here is an example of using headers for having the code split in two source files:
headers don't get compiled, you should compile myheader.cpp, main.cpp and link them (If you are using VC++ IDE and these files are in the same project you just need to build the project)
main.cpp is the main file (with the program entry point)
myheader.cpp is the file with the body of the function declared in myheader.h
How can I know that the header file is good and working.Like for .cpp file I can compile and check it but you said we cannot compile .h files. so how can I know that it has linked with .ccp file.