Mail Archives: djgpp/1998/09/04/06:39:07
> Hey guys:
>
> I have not been able to get any C++ programs compiled - and on the DJGPP
> website, it says that gcc should know what to to with the file according
> to the file's extenstion. I tried to compile a simple C++ program that
> couts one line (it looks like this):
>
> #include <iostream.h>
>
> main(void)
> {
> cout << "This is a test.";
> }
C++ is VERY picky about implicit declarations. It will throw a wobbley if
you don't define main() as int main() (any function parameters not declared
will be counted as void in C++, but not in C). main() always returns an int
(even in C), but C won't shout at you half as much as C++ will. Also note
that at the end of the program you must have a return 0; or something to
shouw that it exits properly.
And more picking with your code. C++ standards state that you should output
an endl at the end of each line you stream to the stdout.
gcc will not link with the C++ libraries according to extension. To do this
you must use gxx (which will).
So your code should be:
#include <iostream.h>
int main()
{
cout << "This is a test." << endl;
return 0;
}
and then compile it with gxx.
HTH
James Arthur
jaa AT arfa DOT clara DOT net
ICQ#15054819
- Raw text -