c++简单包含头文件

来源:百度知道 编辑:UC知道 时间:2024/06/06 08:02:44
设计一程序,将求两个实数的最大值函数放在头文件myfun.h中,在源程序文件mypro.cpp中包含该头文件,并实现输入三个实数,求出最大值。

怎么做的呢?

从最特殊到最一般,也就是,
#include "本类头文件"
#include "本目录头文件"
#include "自己写的工具头文件"
#include "第三方头文件"
#include "平台相关头文件"
#include "C++库头文件"
#include "C库头文件"

定义宏函数比较好
//mufun.h
#ifndef MYFUN
#define MYFUN
#define fun(a,b,c) {if(a>b)\
if(a>c)\
cout<<"the max = a";\
else \
cout<<"the max = c";\
else \
if(b>c)\
cout<<"the max = b";\
else \
cout<<"the max = c";\
}
#endif

//mypro.cpp

#include "iostream.h"
#include "myfun.h"

main()
{
int a = 3;
int b = 4;
int c = 5;
fun(a,b,c);

}
两个文件要在一个工作区里。
好好学习。

把函数声明写在头文件
myfun.h

void add