LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 730|回复: 6

somebody help me!!!

[复制链接]
发表于 2004-12-10 15:30:36 | 显示全部楼层 |阅读模式
about the head file problem. gcc always say missing head file, such as iostream.h. and I find it in g++-3 folder. so I copy it to include folder. and the missing file problem gone. but there are lots of errors. what's going on?

just like a simple program:

#include <iostream.h>
#define max 10
int main()
{
#if max>99
        cout<<"max is great";
#else
        cout<<"max is small";
#endif
return 0;
}

when gcc -c xxxx.c, it display:

In file included from /usr/include/iostream.h:31,
                 from test1.c:1:
/usr/include/streambuf.h:35: parse error before string constant
In file included from /usr/include/_G_config.h:44,
                 from /usr/include/libio.h:32,
                 from /usr/include/streambuf.h:36,
                 from /usr/include/iostream.h:31,
                 from test1.c:1:

and so many errors......
somebody help me!!
发表于 2004-12-10 17:51:13 | 显示全部楼层
iostream.h is one of c++ develop header files.  Your file name is xxx.c not xxx.C or XXX.cc or XXX.c++ and you used "gcc" as compile command. GCC will trade xxx.c as C source file, so that c++ include path will be ignored, and iostream.h can't be found.

Copy iostream.h to your source directory goes far away from the right way, because you don't know if iostream.h includes other files or not and you don't know relative  path is used or absolute path is used. It may bring more errors to you.

conclusion:
1. C++ source code file should be saved in form of xxx.C or xxx.cc or xxx.c++
2. use g++ to compile your c++ code.
发表于 2004-12-12 00:40:48 | 显示全部楼层
请尽量不要使用宏来定义常量。
发表于 2004-12-12 11:29:16 | 显示全部楼层
最初由 herberteuler 发表
请尽量不要使用宏来定义常量。

C++提倡尽量不用宏。在C 中用宏定义常量有助于提高可读性。
发表于 2004-12-12 11:34:36 | 显示全部楼层
最初由 kj501 发表
C++提倡尽量不用宏。在C 中用宏定义常量有助于提高可读性。


如果是整数的话,我会使用枚举来定义常量。(我不会 C++)
 楼主| 发表于 2004-12-13 21:11:47 | 显示全部楼层
thx, it seems the promblem come from xxx.c and gcc.
THX!!!!!
发表于 2004-12-14 01:29:38 | 显示全部楼层
for c++ user, you should use <iostream>
iostream.h is just for downward compatibility.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表