c++中的头文件的使用用法实例源码

c++中的头文件的使用用法实例源码,c++中的头文件的使用可以使项目更加清晰可读,增强代码的复用度,这里我们我讨论c++中使用头文件的好处而是老举例说明头文件的用法:

首先是c++头文件代码,定义头文件HuMan.h

#include<iostream>//c++头文件引入iostream
using namespace std;
class A
{
public:
void func(int x,int y){i=x;j=y;}
void print(){cout <<”两数相乘为:”<<i*j<<endl;}
private:
int i;
int j;
};

c++源代码human.cpp使用头文件实例;

#include “HuMan.h”//从当前项目中读入头文件
int main()
{
A a;
a.func(100,898);
a.print();
} 本文链接地址: c++中的头文件的使用用法实例源码