fstream.h and iostream.h

B

bintom

On Turbo C++, the following program works:

#include <fstream.h>
#include <conio.h>

int main( )
{ cout << "abc";
return 0;
}


However, in Dev C++, I need to add the line:

#include <iostream.h>

Why is this so?

Thanks,
Bintom
 
R

Richard

[Please do not mail me a copy of your followup]

bintom <[email protected]> spake the secret code
On Turbo C++, the following program works:

#include <fstream.h>
#include <conio.h>

int main( )
{ cout << "abc";
return 0;
}

It shouldn't work because you haven't brought namespace std into
scope.

Furthermore, the headers should be <fstream> and <iostream> and not
However, in Dev C++, I need to add the line:

#include <iostream.h>

Because <iostream> is the standard header that declares std::cout.

See "C++ Standard Library" by Nicolai Josuttis for an excellent
reference on the standard library. <http://tinyurl.com/josuttis>
 
I

Ian Collins

On Turbo C++, the following program works:

#include<fstream.h>
#include<conio.h>

int main( )
{ cout<< "abc";
return 0;
}

This would work in some pre-standard compilers, before iostreams were
brought into the std namespace. So I guess you have an old compiler
where said:
However, in Dev C++, I need to add the line:

#include<iostream.h>

Why is this so?

That one doesn't include <iostream.h> in <fstream.h>

As stated else-thread, the correct header is <iostream>
 
V

Victor Bazarov

[Please do not mail me a copy of your followup]

bintom<[email protected]> spake the secret code
On Turbo C++, the following program works:

#include<fstream.h>
#include<conio.h>

int main( )
{ cout<< "abc";
return 0;
}

It shouldn't work because you haven't brought namespace std into
scope.

Actually the headers <fstream.h> and <iostream.h> (and other in the form
<{standardname}.h>) used to exist in some implementations before they
supported the 'std' namespace (or before the 'std' namespace was even
introduced for all standard declarations). Turbo C++ is one of those
implementations, I am guessing.
Furthermore, the headers should be<fstream> and<iostream> and not


Because<iostream> is the standard header that declares std::cout.

See "C++ Standard Library" by Nicolai Josuttis for an excellent
reference on the standard library.<http://tinyurl.com/josuttis>

Again, Dev C++ version the OP has *may* still contain non-standard
headers with standard names yet with .h extension, and they can either
have explicit 'using namespace std;' after including the corresponding
standard header or just contain everything like the standard one only
without the 'std' namespace.

To the OP: get the book Richard recommended and learn to use *only* the
standard headers for the *standard* elements (classes, objects,
functions, etc.) You will undoubtedly need non-standard stuff, but
stick to the book's style and you're gonna be OK.

V
 
J

James Kanze

Actually the headers <fstream.h> and <iostream.h> (and other
in the form <{standardname}.h>) used to exist in some
implementations before they supported the 'std' namespace (or
before the 'std' namespace was even introduced for all
standard declarations). Turbo C++ is one of those
implementations, I am guessing.

I evaluated a version of it almost 10 years before the standard
was adopted. That's how old it is.
Again, Dev C++ version the OP has *may* still contain
non-standard headers with standard names yet with .h
extension, and they can either have explicit 'using namespace
std;' after including the corresponding standard header or
just contain everything like the standard one only without the
'std' namespace.

Or contain something subtly different. Say, compatible with the
classical iostream, rather than the standard iostream. (It's
not just std::. The classical iostream wasn't a template, some
of the options worked slightly differently, and some of the
functions had different names. Or were missing entirely.)
 
R

Richard

[Please do not mail me a copy of your followup]

Victor Bazarov <[email protected]> spake the secret code
To the OP: get the book Richard recommended and learn to use *only* the
standard headers for the *standard* elements (classes, objects,
functions, etc.) You will undoubtedly need non-standard stuff, but
stick to the book's style and you're gonna be OK.

Additionally, I wrote a blog post about online references for this
sort of thing. <http://tinyurl.com/onlinecppreference>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top