On Thu, Nov 25, 2004 at 08:30:53AM +1100, Nicholas Tomlin wrote:
> Hell sluggers,
Right on.
> ** error message:
> [...]
>
> ** I'm not worried about the antiquated header, The syntax is the issue. I've
> tried all sorts of mods to the syntax and cannot get it to go away, the
> program is a 'cut and paste' straight out of a text book, but it does not
> work! (while student is programming; writeln f..k).
The header isn't antiquated, you don't put the .h on C++ includes. The
.h variant doesn't use namespaces, if you do
#include <iostream>
your header warning will go away. You'll then get a new error, because
you haven't either specified the std namespace for all the std stuff
you're using, nor specified that you want the namespace imported
(assuming you're running a vaguely recent version of g++). So, you can
either do this kinda thing:
std::cout << ...
or put this at the top of the file somewhere:
using namespace std;
Have you intentionally dropped the arguments from main()? Anyway, you
probably want something like this:
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int x = 5;
int y = 7;
cout << x + y << " " << x * y << endl;;
return 0;
}
> I assume this is normal practice, to publish inaccurate and unusable
> programs so some schmuck spends hours sorting it out...
The error you were getting was a missing <<. I'd double check that. The
issue with your header files is probably the age of your references.
There was a long time where g++ would just ignore namespaces and there's
a lot of reference material that still ignores this fact.
HTH,
James.
--
"Now, there are no problems only opportunities. However, this seemed to be an
insurmountable opportunity."
- http://www.surfare.net/~toolman/temp/diagram.html
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html