Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Apr 2003 12:33:35 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Jason Griffis <jgriffis@ec.rr.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: g++ question
Message-ID:  <20030421103334.GA92718@falcon.midgard.homeip.net>
In-Reply-To: <200304210539.11227.jgriffis@ec.rr.com>
References:  <200304210539.11227.jgriffis@ec.rr.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Apr 21, 2003 at 05:39:11AM -0400, Jason Griffis wrote:
> 	I'm going through a C++ tutorial trying to increase my knowledge ;)
> Any way.. I wrote this little code:
> 
> // My first program in C++
> #include <iostream>
> 
> int main()
> {
> 	cout << "Hello World!";
> 	return 0;
> }
> 
> 	When I compile it this way with g++ I get errors due to the compiler not 
> finding the iostream file:
> 
> $ g++ -o hello hello.cc
> hello.cc: In function `int main()':
> hello.cc:6: `cout' undeclared (first use this function)
> hello.cc:6: (Each undeclared identifier is reported only once for each 
> function
>    it appears in.)
> $
> 
> 	I do have iostream in /usr/include so I don't see why it's doing this, 
> whenever I change it to #include <iostream.h> it compiles fine but gives a 
> warning of using a deprecated header file:
> 
> $ g++ -o hello hello.cc
> In file included from /usr/include/g++/backward/iostream.h:31,
>                  from hello.cc:2:
> /usr/include/g++/backward/backward_warning.h:32:2: warning: #warning This file 
> includes at least one deprecated or antiquated header. Please consider using 
> one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples 
> include substituting the <X> header for the <X.h> header for C++ includes, or 
> <sstream> instead of the deprecated header <strstream.h>. To disable this 
> warning use -Wno-deprecated.
> $
> 
> 	Obviously it isn't that big of a deal with such a small program but when I 
> move on to bigger projects that I'll want to use on different platforms other 
> than FreeBSD these errors and warnings will be a major pain. Can anyone tell 
> me what might be wrong with my system in order for g++ not to see the normal 
> iostream header in /usr/include ?

[This is not really a FreeBSD question, but rather a C++ question.]

Nothing wrong with your system, but a problem with your program.
The tutorial you are using seems to be a bit old.
Although your program would have been just fine with older C++
implementations (except that they did not have headernames of the <foo>
style, only <foo.h>) , the newer, standard-compliant, implementations
have moved most of the standard library into the 'std' namespace.
The older <foo.h> name for the headers puts the functions into the
global namespace, but that is not recommended for new code.

Try using std::cout instead of just cout.  (Or put a 'using namespace
std;' after the include.)


-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030421103334.GA92718>