使用G ++编译多个.cpp和.h文件
要一次编译多个文件,例如file_name.h或file_name.cpp,我们可以像列表一样使用文件。语法如下:
g++ abc.h xyz.cpp
要运行程序,我们可以使用它-
./a.out
示例
float area(float r){
return (3.1415*r*r); //area of a circle
}
float area(float l, float w){
return (l * w); //area of a rectangle
}示例
#include <iostream>
#include "area.h"
using namespace std;
main(){
cout << "Area of circle with radius 2.5 is: " << area(2.5) << endl;
cout << "Area of rectangle with length and width are 5 and 7 is: " << area(5, 7) << endl;
}输出结果
$ g++ area.h find_area.cpp $ ./a.out Area of circle with radius 2.5 is: 19.6344 Area of rectangle with length and width are 5 and 7 is: 35 $
热门推荐
10 开工红包祝福语毕业简短
11 中秋祝福语简短有深度
12 关于健康的祝福语简短
13 圣诞贺卡祝福语简短高级
14 学生老师离职祝福语简短
15 卡片朋友祝福语大全简短
16 写给老板祝福语简短高级
17 升大学祝福语简短女生
18 自己祝福语简短唯美短句