From owner-freebsd-questions@FreeBSD.ORG Fri Dec 16 18:04:59 2005 Return-Path: X-Original-To: questions@freebsd.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0022B16A420 for ; Fri, 16 Dec 2005 18:04:58 +0000 (GMT) (envelope-from nvidican@wmptl.com) Received: from wmptl.net (fw1.wmptl.com [216.8.159.129]) by mx1.FreeBSD.org (Postfix) with ESMTP id B180243D5A for ; Fri, 16 Dec 2005 18:04:57 +0000 (GMT) (envelope-from nvidican@wmptl.com) Received: from [10.0.0.104] (r3140ca.wmptl.net [10.0.0.104]) by wmptl.net (8.13.1/8.13.1) with ESMTP id jBGI4mKS098561; Fri, 16 Dec 2005 13:04:48 -0500 (EST) (envelope-from nvidican@wmptl.com) Message-ID: <43A301BF.5040509@wmptl.com> Date: Fri, 16 Dec 2005 13:04:47 -0500 From: Nathan Vidican User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Giorgos Keramidas References: <43A2DE53.7080207@wmptl.com> <979f20140512160813i5394e789u1d7624a625e893f@mail.gmail.com> <979f20140512160709n3530c01dmdad5714f8e30bc00@mail.gmail.com> <43A2DE53.7080207@wmptl.com> <9061.38.112.155.126.1134747675.squirrel@www.keyslapper.net> <979f20140512160709n3530c01dmdad5714f8e30bc00@mail.gmail.com> <43A2DE53.7080207@wmptl.com> <979f20140512160709n3530c01dmdad5714f8e30bc00@mail.gmail.com> <43A2DDCF.1030708@wmptl.com> <979f20140512160709n3530c01dmdad5714f8e30bc00@mail.gmail.com> <20051216170046.GB2712@flame.pc> In-Reply-To: <20051216170046.GB2712@flame.pc> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.111 () RATWR10_MESSID X-Scanned-By: MIMEDefang 2.44 Cc: davmiao@gmail.com, questions@freebsd.org Subject: Re: C++ compile error X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Dec 2005 18:04:59 -0000 Giorgos Keramidas wrote: > On 2005-12-16 23:09, 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) > > >>==quote of hello world code== >>#include >> >>int main() >>{ >> cout << "Hello World!" << endl; >> >> return 0; >>} >>== end of quote== > > > You have to add a line like this: > > using namespace std; > > at the toplevel of your sources. The example then works: > > keramida@flame[18:51]/tmp$ CC hello.C > keramida@flame[18:52]/tmp$ ./a.out > Hello World! > keramida@flame[18:52]/tmp$ diff -u hello.C.orig hello.C > --- hello.C.orig Fri Dec 16 18:51:26 2005 > +++ hello.C Fri Dec 16 18:51:58 2005 > @@ -1,5 +1,7 @@ > #include > > +using namespace std; > + > int main() > { > cout << "Hello World!" << endl; > keramida@flame[18:52]/tmp$ > > On 2005-12-16 10:31, Nathan Vidican wrote: > >>gcc assumes a '.C' file is ANSI C, not C++, try: >>mv hello.C hello.cpp && gcc -o hello.exe hello.cpp > > > Not really. But it's a very good idea to use something that doesn't > only differ in the case of the name from plain ANCI C, because > transferring the files from Unix to other operating systems > (i.e. Windows) may lose the case of the names some times :-) > > On 2005-12-16 10:41, "Louis J. LeBlanc" wrote: > >>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? > > > It doesn't :-( > > On 2005-12-17 00:13, David Miao wrote: > >>Nathan, >> >>I'm learning c++ programming language by using "The complete c++ >>training course - second edition" (Harvey Deitel & Paul Deitel), hello >>world is the first program in this book. I'm totally puzzled by this >>complex language when I compile my first program. Is this book out of >>date? > > > That's a pretty old book. Judging from the sheer number of books these > authors have listed in Amazon, I think it's pretty safe to consider it > very out of date :( > > >>This post may off topic of FreeBSD, sorry to other people... > > > That's ok. The list is, after all, "for general FreeBSD questions" :) > > > If you want a GOOD book to start self-teaching C++, grab yourself 'C++ in 21 Days' it's a classic, but GREAT starter book. -- Nathan Vidican nvidican@wmptl.com Windsor Match Plate & Tool Ltd. http://www.wmptl.com/