- 论坛徽章:
- 0
|
最近看《c++大学教程》
在P.278时看到它说将程序分解为多个文件,再编译和链接,代码如下:
// time1.h
// Declaration of the Time class.
#ifndef TIME1_H
#define TIME1_H
class Time
{
public:
Time();
void setTime( int, int, int );
void printMilitary();
void printStandard();
private:
int hour;
int minute;
int second;
};
#endif
// time1.cpp
// Member function definitions for Time class
#include <iostream.h>
#include "time1.h"
Time::Time(){ hour = minute = second = 0; }
void Time::setTime( int h, int m, int s )
{
hour = ( h >= 0 && h < 24 ) ? h : 0;
minute = ( m >= 0 && m < 60 ) ? m : 0;
second = ( s >= 0 && s < 60 ) ? s : 0;
}
void Time::printMilitary()
{
cout << ( hour < 10 ? "0" : "" ) << hour << ":"
<< (minute < 10 ? "0" : "" ) << minute;
}
void Time::printStandard()
{
cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 )
<< ":" << ( minute < 10 ? "0" : "" ) << minute
<< ( hour < 12 ? " AM" : " PM" );
}
// text.cpp
// Driver for Time1 class
// Compile with time1.cpp
#include <iostream.h>
#include "time1.h"
int main()
{
Time t;
cout << "The inital military time is";
t.printMilitary();
cout << "The inintal standard time is";
t.printStandard();
t.setTime(13,27,6);
cout << "\n\nMilitay time after setTime is";
t.printMilitary();
cout << "\n\nStandard time after setTime is";
t.printStandard();
t.setTime(99,99,99);
cout << "\n\nAfter attempting invalid setting:\n"
<< "Military time:";
t.printMilitary();
cout << "\nStandard time:";
t.printStandard();
cout << endl;
system("pause");
return 0;
}
红色一行说要一起编译,可我没找到。
请问在c++builder中怎么多个文件一起编译?
[ 本帖最后由 kid@B_Sky 于 2007-9-12 10:41 编辑 ] |
|