假如我要写一个交换变量值并输出的函数swap
    分四个步骤

    • 创建.h头文件
    • 创建.cpp源文件
    • 在头文件中写函数的声明
    • 在源文件中写函数的定义

    swap.h

    1. #pragma once
    2. #include<iostream>
    3. using namespace std;
    4. void swap(int a, int b);

    swap.cpp

    #include"swap.h"
    void swap(int a, int b) {
        a ^= b;
        b ^= a;
        a ^= b;
        cout << a << " " << b << endl;
    }
    

    main.cpp

    #include <iostream>
    #include"swap.h"
    using namespace std;
    int main() {
        swap(1,2);
    }
    

    输出结果
    image.png