include external file in C++

How to include external file in to your C++ program:

1. Create an external file and save it with h extension in include directory.
The include directory can be found in your installation directory.
Example: your myTriangle.h file contains the printTriangle function as shown below:

int printTriangle(){

int i,j;
for(j=1;j<=i;j++) cout<<"*";


2. To use the printTriangle function in your C++ program, you must include the myTriangle.h file in your program:
using namespace std;
int main(){

return 0;

Posted by: Dara | post date: 12-09-2012 | Subject: C++ Programming Language

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.