LinuxSir.cn,穿越时空的Linuxsir!

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

为什么我的"hello world"通过不了编译??!!

[复制链接]
发表于 2003-3-6 18:46:47 | 显示全部楼层 |阅读模式
我刚装上readhat linux 8.0。
然后
$ vi hello.cpp

// 以下为源代码
#include<iostream>
int main()
{
  cout<<"hello world "<<endl;
return 0;
}//end of code

$g++ -o hello hello.cpp
编译器提示cout .endl undefine
为什么会出现这种情况?
发表于 2003-3-6 19:43:13 | 显示全部楼层
using namespace std;
 楼主| 发表于 2003-3-6 21:18:00 | 显示全部楼层
我试过了,

加上下列语句也不行

#include <stdlib.h>
using namespace std;

都不行,

$find /usr -name "iostream.h" -print
又可以找到iostream.h文件。
发表于 2003-3-6 22:35:20 | 显示全部楼层
把cout改成std::cout,把endl改成std::endl。我就是这么做的。
 楼主| 发表于 2003-3-7 07:54:13 | 显示全部楼层
kj501:谢谢你,我的程序已经通过了编译,但是你能不能告诉我,为什么加上命名空间不行,单独指定却行呢,按道理你的做法和” using namespace std"是一致的呀,而后都却行不通呢?
发表于 2003-3-7 09:04:28 | 显示全部楼层

Re: 为什么我的&quot;hello world&quot;通过不了编译??!!

最初由 aweil 发布
我刚装上readhat linux 8.0。
然后
$ vi hello.cpp

// 以下为源代码
#include<iostream>
int main()
{
  cout<<"hello world "<<endl;
return 0;
}//end of code

$g++ -o hello hello.cpp
编译器提示cout .endl undefine
为什么会出现这种情况?

iostream好象少了个.h吧
发表于 2003-3-7 10:18:27 | 显示全部楼层
最初由 aweil 发布
kj501:谢谢你,我的程序已经通过了编译,但是你能不能告诉我,为什么加上命名空间不行,单独指定却行呢,按道理你的做法和” using name std"是一致的呀,而后都却行不通呢?

应该是using namespace std,而不是using name std。
 楼主| 发表于 2003-3-7 11:38:57 | 显示全部楼层
谢谢各位大侠的帮助!!!此帖到此为止了,
发表于 2003-3-7 11:40:12 | 显示全部楼层
是 #include <iostream.h> 吧。
发表于 2003-3-7 23:10:16 | 显示全部楼层
#include <iostream>
是正确的,C++的标准现在是没有 .h 的。<iostream.h>也可以编译,那是因为保持兼容性。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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