作用: 让代码结构更加清晰

    步骤:

    1. 创建后缀名为 .h 的头文件
    2. 创建后缀名为 .cpp 的源文件
    3. 在头文件中写函数申明
    4. 在源文件中写函数定义

    head.h

    1. #include <iostream>
    2. using namespace std;
    3. //计算两个数的合
    4. void sum(int a, int b);

    head.cpp

    1. #include "head.h"
    2. void sum(int a, int b) {
    3. int sum = a + b;
    4. printf("%d",sum);
    5. }

    use.cpp

    1. #include <iostream>
    2. using namespace std;
    3. #include "head.h";
    4. int main() {
    5. sum(10,20);
    6. }