Date: Fri, 16 Dec 2005 10:31:27 -0500 From: Nathan Vidican <nvidican@wmptl.com> To: David Miao <davmiao@gmail.com> Cc: questions@freebsd.org Subject: Re: C++ compile error Message-ID: <43A2DDCF.1030708@wmptl.com> In-Reply-To: <979f20140512160709n3530c01dmdad5714f8e30bc00@mail.gmail.com> References: <979f20140512160709n3530c01dmdad5714f8e30bc00@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
David Miao wrote:
> Dear list,
>
> I try to compile a hello world C++ program in FreeBSD 6.0, but get an
> error as below:
>
> [dm@ORION ~/cpp]% CC -o hello hello.C
> hello.C: In function `int main()':
> hello.C:5: error: `cout' undeclared (first use this function)
> hello.C:5: error: (Each undeclared identifier is reported only once
> for each function it appears in.)
> hello.C:5: error: `endl' undeclared (first use this function)
>
> I noticed that "iostream" file is located in
> "/usr/include/c++/3.4/iostream", I guess my CC compiler cannot find
> this head file. Is it true? And how can I fix this problem? Your
> advice is appreciated. Thanks in advance.
>
> ==quote of hello world code==
> #include <iostream>
>
> int main()
> {
> cout << "Hello World!" << endl;
>
> return 0;
> }
> == end of quote==
>
> Regards,
> David
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
>
>
>
gcc assumes a '.C' file is ANSI C, not C++, try:
mv hello.C hello.cpp && gcc -o hello.exe hello.cpp
simple hellow world:
#include <iostream.h>
using namespace std;
int main(int argc,char* argv[]) {
cout << "Hello World!" << endl;
return 0;
}
// end of file
Should work - reply if not :)
--
Nathan Vidican
nvidican@wmptl.com
Windsor Match Plate & Tool Ltd.
http://www.wmptl.com/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?43A2DDCF.1030708>
