|
发表于 2006-8-15 22:09:14
|
显示全部楼层
[quote:6190d60e8b="genedemon"]好像还是有点问题:)
下面是输入的cpp文件,文件名是NONAME00,是我在win下面的Turbo C++3.0写的
[root@MagicLinux2 C++]# g++ -o NONAME00 NONAME00.CPP
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/backward/iostream.h:31,
from NONAME00.CPP:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
NONAME00.CPP:7: error: `main' must return `int'
不知道为什么说有错,是不是Linux下的语法和win下面的语法要求不同?
源代码是:
#include <iostream.h>
int max(int a,int b);
int max(int a,int b,int c);
int max(int a,int b,int c,int d);
void main()
{
cout<<max(2,4)<<endl;
cout<<max(4,5,6)<<endl;
cout<<max(2,4,5,6)<<endl;
}
int max(int a,int b)
{
return a>b?a:b;
}
int max(int a,int b,int c)
{
int t=max(a,b);
return max(t,c);
}
int max(int a,int b,int c,int d)
{
int t1=max(a,b);
int t2=max(t1,c);
return max(t2,d);
}
在win下面编译是成功的[/quote]
可能是你在win下的编译器并不是严格遵守标准cpp语法,而gnu c是完全支持的,记得我原来也犯了你一样的错误,本来已经在vc++ 6.0中编好的程序,再用gcc作编译器的dev c++中怎么也通不过,后来发现就是你这个问题,main函数需要返回值。
这个也不能怪lz,现在很多书籍包括我当时的大学教科书上,这种程序例子是比比皆是,感慨一下中国的教育... |
|