清丰网站建设,腾和企业网站管理系统,合二为一的创意产品设计,如何将网站做成app项目的目录结构 头文件swap.h
在自定义的头文件中写函数的声明。
// 函数的声明
void swap(int a,int b);swap.cpp
导入函数的声明#xff0c;写函数的定义
#include swap.h // 双引号表示自定义的头文件
#include iostream
using namespace std;// 函…项目的目录结构 头文件swap.h
在自定义的头文件中写函数的声明。
// 函数的声明
void swap(int a,int b);swap.cpp
导入函数的声明写函数的定义
#include swap.h // 双引号表示自定义的头文件
#include iostream
using namespace std;// 函数的定义
void swap(int a,int b)
{int tempa;a b;b temp;cout aaendl;cout bbendl;
}main.cpp
主函数
#include iostreamusing namespace std;
#include swap.h
// 函数的分文件编写// // 函数的声明
// void swap(int a,int b);// // 函数的定义
// void swap(int a,int b)
// {
// int tempa;
// a b;
// b temp;
// cout aaendl;
// cout bbendl;
// }int main()
{int a10;int b20;swap(a,b);return 0;
}编译
按ctrl 打开终端 输入以下命令进行编译
g main.cpp src/swap.cpp -Iinclude -o main-I是指定头文件所在的目录include此处是头文件swap.h放置的目录。 g后面是要编译的文件main和src目录下的文件都要编译。
运行
终端中输入以下命令
./main