www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/04/06:39:07

Reply-To: <arfa AT clara DOT net>
From: "Arthur" <arfa AT clara DOT net>
To: "DJGPP Mailing List" <djgpp AT delorie DOT com>, "Jason" <jpsaave AT sandia DOT gov>
Subject: RE: Why doesn't C++ work!?!?!
Date: Fri, 4 Sep 1998 11:38:53 +0100
Message-ID: <000101bdd7f0$3648b760$ca4e08c3@arthur>
MIME-Version: 1.0
In-reply-to: <35EF0D07.DC9983E1@sandia.gov>
Importance: Normal

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019