Date: Fri, 16 Dec 2005 11:24:40 -0600 From: "Harley D. Eades III" <hde@foobar-qux.org> To: freebsd-questions@FreeBSD.org Cc: David Miao <davmiao@gmail.com>, questions@freebsd.org, Nathan Vidican <nvidican@wmptl.com> Subject: Re: C++ compile error Message-ID: <1134753880.34653.48.camel@devilBSD.freeBSD> In-Reply-To: <9061.38.112.155.126.1134747675.squirrel@www.keyslapper.net> References: <979f20140512160709n3530c01dmdad5714f8e30bc00@mail.gmail.com> <43A2DE53.7080207@wmptl.com> <9061.38.112.155.126.1134747675.squirrel@www.keyslapper.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 2005-12-16 at 10:41 -0500, Louis J. LeBlanc wrote: > On Fri, December 16, 2005 10:33 am, Nathan Vidican wrote: > > 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" > >> > >> > >> > > > > Also, noticed your code is flawed, you never used a namespace, nor > > explicitly stated one. cout is part of the 'std' namespace, so either > > ' using namespace std;' for global/local use of namespace, OR do > > 'std::cout <<' instead. Try the hello.cpp I sent you in the last email, > > that one should work for ya :) > > I'm not nearly as adept with C++ as I am with C, Perl, and a few other > geek tools, but doesn't C++ default to the std namespace if none is > specified? > > Perhaps this is a compiler specific behavior? No, you have to either tell the compiler by using "std::METHOD" or say using namespace std; to annouce you are using std as your primary namespace. -- Harley -----BEGIN GEEK CODE BLOCK----- G: GCS-- d- a? C++++ B- E+++ W+++ N++ w--- X+++ b++ G e* r x+ z+++++ ------END GEEK CODE BLOCK------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1134753880.34653.48.camel>