使用 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 $
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP