免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1332 | 回复: 2
打印 上一主题 下一主题

新手请教一个问题: [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-01-17 12:35 |只看该作者 |倒序浏览
程序如下:
/*This is a sample C++ program
*Arramy.CPP*/

#include </usr/include/g++/iostream.h>;
#include </usr/include/time.h>;
#include </usr/include/stdlib.h>;

int Num(void);

int main(){
        /*
        int ZS; //ZS is the number you choice the total of your choose;
        int rad; //rad is the a number between 1 to 35;
        cout << "\n\nPlease input a number between 1 to 100 :" << endl;
        cin >;>; ZS;
        cout << "\n" << endl;
        */
        /*following program will get some number for you CaoPiao; */
        /*
        cout << "\n\n===================================" << endl;
        for ( int i=0; i<ZS; i++){
                for ( int j=0; j < 5; j++){
                        rad = Num();
                        cout << rad << "\b" << endl;
                }
                cout << "\n" << endl;
        }
        */
        cout<<"\n\n=====Hello==============================" << endl;
}

int Num(void){
        int k,s;
        s = time(0);
        k = rand()%35 +1;
        return k;       
}






我在FreeBSD下面用gcc编译的时候提示:
/tmp/ccW47lTD.o: In function `main':
/tmp/ccW47lTD.o(.text+0xa): undefined reference to `endl(ostream &amp'
/tmp/ccW47lTD.o(.text+0x17): undefined reference to `cout'
/tmp/ccW47lTD.o(.text+0x1c): undefined reference to `ostream:perator<<(char const *)'
/tmp/ccW47lTD.o(.text+0x27): undefined reference to `ostream:perator<<(ostream &amp;(*)(ostream &amp)'




我的问题是:FreeBSD下面的io流的库不是iostream.h这个么?
应该用哪一个库呢?谢谢

论坛徽章:
0
2 [报告]
发表于 2003-01-17 12:45 |只看该作者

新手请教一个问题:

是用g++编译。
g++ -o Arramy Arramy.cpp

论坛徽章:
0
3 [报告]
发表于 2003-01-17 13:00 |只看该作者

新手请教一个问题:

修改
#include <iostream.h>;
#include <time.h>;
#include <stdlib.h>;

using namespace std;

C++中引入了namespace 概念
旧的标准流都被包含在name space std 中
不写头文件路径名编译器一样可以找到
另外头文件不应该写路径名
为了移植方便
因为可能有的人的标准头文件不在/usr/include目录下

还有正如liupch  说的应该用g++ 编译c++程序
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP