免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2872 | 回复: 2

[C++] c++builder编译多个文件的问题 [复制链接]

论坛徽章:
0
发表于 2007-09-11 23:25 |显示全部楼层
最近看《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 编辑 ]

论坛徽章:
0
发表于 2007-09-11 23:32 |显示全部楼层
是不是把它放一个工程就一起编译了呢?

论坛徽章:
0
发表于 2007-09-12 10:40 |显示全部楼层
谢谢了。
不过不好意思,我不会把把它们放到一个工程文件里。
但好像只要在text.cpp中加入:
#include "time1.cpp"就可以了。

好像还可以把所有文件编译了再链接,可惜我也不会。
再次感谢。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP