2005-12-1 13:30
surges
第一次用C++在LINUX下编译的问题
代码如下:
[color=Red]
#include <iostream.h>
void main()
{
int i=1,sum=0;
while(i<=100)
{
sum=sum+i;
i=i+1;
}
cout<<"sum="<<sum<<endl;[/color]
用secureCRT在LINUX下编译得到结果为:
[color=Green]/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
test_2.cpp:4: `main' must return `int'
test_2.cpp:13:3: warning: no newline at end of file[/color]
在Windows 下用VC++6.0编译通过,这里就是看不懂错在那里啊?
请大家指教一下~~~~
谢谢!
2005-12-1 14:11
自然平衡
#include <iostream.h>
C++标准库的头文件名是没有.h的。
test_2.cpp:4: `main' must return `int'
程序没有返回值。
另外你忘记使用名字空间(namespace)了。
2005-12-1 14:16
surges
namespace?
没有用过啊!
大哥你能把我个程序改成一个正确的代码吗?
2005-12-1 14:25
自然平衡
[code]
#include <iostream>
using namespace std;
int main()
{
int i=1,sum=0;
while(i<=100)
{
sum=sum+i;
i++;
}
cout << "sum=" << sum << endl;
return 0;
}
[/code]
2005-12-1 14:37
surges
我调试了你的代码
我用以下代码和你的代码效果一样
[color=Red]#include <iostream.h>
int main()
{
int i=1,sum=0;
while(i<=100)
{
sum=sum+i;
i=i+1;
}
cout<<"sum="<<sum<<endl;
} [/color]
在编译的结果中显示为:
[color=Green]test_2.cpp:16:2: warning: no newline at end of file[/color]
但这个好象并没什么影响,依然能的到结果!
这个警告代表的是什么意思呢?:L
还有,在我的代码中没有实现namespace名字空间~~
大哥你能指点一下,我这个代码从编程这个角度是否有错?
[[i] 本帖最后由 surges 于 2005-12-1 14:50 编辑 [/i]]
2005-12-1 15:29
自然平衡
在我的Linux系统上可以通过的,不知道你是否是在windows下保存源码的,如果是,请试试在linux系统下建立源码文件,可能是文件格式问题。
namespace在写练习程序时可能会觉得罗嗦麻烦,但是在软件项目中是很有用的。
2005-12-1 15:44
surges
刚才问了其他人 ,明白警告的出现是因为在 LINUX下 在最后一行加顶格空行!
呵呵!
大哥 ,你真行!:victory::victory:
有联系方式吗?
QQ?
抑或其他 ?
想随时找你请教你 :handshake
2005-12-1 15:58
自然平衡
共同进步!
QQ倒是有,但我几乎都不用了,上网几乎就是泡论坛,所以不好意思哈!:)
[email]exnaba@gmail.com[/email]
2005-12-1 16:21
surges
呵呵 ,我也很喜欢泡论坛的,只是这几天很少有时间上网,QQ到是天天上,不过也是挂起的,没怎么用...
你每天都挂在这个论坛上面吗?
是的话,我有什么问题就来论坛找你请教啊
不是的话,我就发邮件给你
希望你能不吝赐教啊!~~~~:handshake
页:
[1]
Powered by Discuz! Archiver 5.5.0
© 2001-2006 Comsenz Inc.