
//1.创建.h头文件
//2.创建.cpp源文件
//3.头文件中写函数声明
//4.源文件写函数定义]
#include<iostream>
using namespace std;
#include"swap.h"
int main() {
int a = 2;
int b = 3;
swap(a, b);
system("pause");
return 0;
}
//1.创建.h头文件
//2.创建.cpp源文件
//3.头文件中写函数声明
//4.源文件写函数定义
#include"swap.h"
void swap(int a, int b) {//函数的定义
int temp = a;
a = b;
b = temp;
cout << "a=" << a << endl;
cout << "b=" << b << endl;
}
#include<iostream>
using namespace std;
void swap(int a, int b);//函数的声明
本文介绍如何在C++中创建头文件和源文件,展示函数声明与定义,以swap函数为例,通过实际代码演示了如何交换两个整数变量的值。通过`#include`包含头文件,展示了标准输入输出和`system(pause)`暂停程序。

2149

被折叠的 条评论
为什么被折叠?



