How to Compile a .CPP With a Header File
A file with the .CPP file extension is a C++ source code file. A header file may be called by the .CPP file and compiled along with the source code file using the C++ compiler. The C++ header file is normally identified by a file extension of ".h." To compile a .CPP source code file with a header file, you call the header file from within the .CPP file using the "include" statement at the top of the .CPP code file.
Instructions
-
-
1
Right-click on the .CPP file and click "Open With" from the context menu.
-
2
Click the "Notepad" option to open the .CPP file in the text editor.
-
-
3
Type the following line at the top of the .CPP file, where "header.h" is the name of your header file:
#include <header.h>
-
4
Click the "File" option on the top navigation bar in Notepad, and then click "Save" to save the .CPP file.
-
5
Open the Microsoft Visual Studio Command Prompt by clicking the Windows "Start" button, and then clicking "All Programs. Click "Microsoft Visual Studio 2010" and then click "Visual Studio Tools." Finally, click the "Visual Studio 2010 Command Prompt" to open a window with the VS command prompt.
-
6
Type "cl file.cpp" (without quotes) where "file" is the name of your .CPP file. Press the "Enter" key. The header file is called by the source code (.CPP) file and compiled into an executable (.EXE) program named "file.exe."
-
7
Double-click the executable (.EXE) file to run and test the program.
-
1