作用: 让代码结构更加清晰
步骤:
- 创建后缀名为 .h 的头文件
- 创建后缀名为 .cpp 的源文件
- 在头文件中写函数申明
- 在源文件中写函数定义
head.h
#include <iostream>using namespace std;//计算两个数的合void sum(int a, int b);
head.cpp
#include "head.h"void sum(int a, int b) {int sum = a + b;printf("%d",sum);}
use.cpp
#include <iostream>using namespace std;#include "head.h";int main() {sum(10,20);}
