**作用:**让代码结构更加清晰
函数分文件编写一般有4个步骤
- 创建后缀名为.h的头文件
- 创建后缀名为.cpp的源文件
- 在头文件中写函数的声明
- 在源文件中写函数的定义
1、在头文件中申明函数
common.h
#include <iostream>
using namespace std;
//函数声明
int GetMaxint(int a ,int b);
2、在.cpp的源文件定义函数
Common.cpp
#include "Common.h"
int GetMaxint(int a, int b) {
int maxint = a > b ? a : b;
return maxint;
}
3、在demo1.cpp引用
#include <stdio.h>
#include<winscard.h>
#include <iostream>
#include "Common.h" //添加自己的头文件
using namespace std;
int main() {
cout << GetMaxint(10,20) << endl;
system("pause");
return 0;
}