Re: makefile to get iostream.h, etc
g++ 3.0 and later follow the ISO/ANSI standard, as do Borland's compilers,
and to a lesser extent, Microsoft Visual C++.
If you are using any ISO compliant comiler, dropping the .h is the corrct
thing to do, BUT if you do, you must remember that standard compliant
compilers put names from headers without the .h into a structure called a
namespace, with the namespace name std.
Compilers that claim compliance wtih the standard are supposed to put
names from header files with .h extensions into the global namespace which
is accessible everywhere. With the huge librarires C++ has, you can have
name clashes between your names and the library names in a large
project. Namespaces are to help prevent the nameclashes.
Most compilers maintain the .h header files for backward
compatiblity, and you can use them if you like. It is better C++ style to
use the headers without the .h.
So, if you use headers without the .h, you them must make the names
(that are then in the namespace std) available with the statement
using namespace std;
Put this outside any function or class, anywhere after you #include the
header but prior to any function, class, or declaration that ues the
name from namespace std;. There are some niceties that you could do to
keep names from being available in the entire file, but until you have a
better grip on C++ don't worry about this. Just do it the easy way.
With most modern compilers, most access to libraries in most C++ compilers
is automatic. Even when it is not, you normally use compiler switches to
make the compiler search a library. Access to header files is also
automatic. The preprocessor does that, following the #include directive.
Email me privately, I'll try to help you if you like.
On Fri, 28 Jun 2002, Brian Nelson wrote:
> Date: Fri, 28 Jun 2002 18:27:06 -0400
> From: Brian Nelson <email@example.com>
> Subject: Re: makefile to get iostream.h, etc
> Resent-Date: Fri, 28 Jun 2002 18:27:52 -0400
> Resent-From: firstname.lastname@example.org
> "Paul Scott,,," <email@example.com> writes:
> > Hi,
> > I have been working on a program to recover some data from a broken ext2
> > partition. I have been using streaming objects.
> > When I compile with g++ with no options the header files iostream.h and
> > fstream.h are found just fine.
> > I am now trying to write a makefile which I haven't done for many years
> > and not on a Linux system. I get:
> > fixext2fs.c:1: iostream.h: No such file or directory
> > fixext2fs.c:2: fstream.h: No such file or directory
> > fixext2fs.c:3: iomanip.h: No such file or directory
> > In file included from fixext2fs.c:8:
> > Ext2fs.h:4: fstream.h: No such file or directory
> > In file included from Ext2fs.h:7,
> > from fixext2fs.c:8:
> > display.h:4: iostream.h: No such file or directory
> > display.h:6: sstream: No such file or directory
> > display.h:7: fstream.h: No such file or directory
> > make: *** [fixext2fs.o] Error 1
> First of all, drop the .h extension from the #include directives. They
> are deprecated in C++. They should like like:
> #include <iostream>
> #include <fstream>
> > How do I tell the makefile how to find these?
> Brian Nelson <firstname.lastname@example.org>
> To UNSUBSCRIBE, email to email@example.com
> with a subject of "unsubscribe". Trouble? Contact firstname.lastname@example.org
To UNSUBSCRIBE, email to email@example.com
with a subject of "unsubscribe". Trouble? Contact firstname.lastname@example.org