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(i=1;i<10;i++){
for(j=1;j<=i;j++) cout<<"*";
cout<<"\n";
}

}

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

printTriangle();
getch();
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.