Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I was reading another thread where a guy asked about C++ books for beginners, and one of the programmers answering wrote this:

Some warnings: avoid all books that present an "hello world" stating with

#include <iostream.h>

I opened my C++ book and sure enough it included the iostream header like the example above.

Why is that bad? What other pointers should I keep in mind when learning C++?

Background: I am proficient with C and I'll start to learn C++ this next semester.

share|improve this question
2  
Another, related pointer, is to include cstdio, not stdio.h (the latter is deprecated). –  Anton Golov Dec 26 '11 at 17:25
4  
@AntonGolov Opinions differ. Many experts prefer <stdio.h> as there is no technical reason why <cstdio> should be prefered. –  Sjoerd Dec 26 '11 at 22:59
add comment

4 Answers 4

up vote 27 down vote accepted

The header iostream.h is a non-standard header and does not exist on all platforms. As a matter of fact it does not exist on my system (using g++ and the GNU libstdc++). So any code using it would simply not compile on my system.

The iostream.h header used to be common before C++ was first standardized in 1998. But since the 98 standard used <iostream> instead of <iostream.h>, the latter has fallen out of favor (being non-standard and all) and is no longer supported on all platforms. Code that uses it should be considered non-standard legacy code and is not portable. Books that teach it should be considered outdated and avoided.

share|improve this answer
10  
I wouldn't avoid a book outright just because of a trivial preprocessor syntax issue. It could be a great book while a terrible book could be using the modern syntax. –  Lord Tydus Dec 26 '11 at 13:19
12  
@Lord Tydus The fact that any given pre-98 book could be a great book does not negate the fact that statistically, you would be better off avoiding pre-98 books. –  Mike Nakis Dec 26 '11 at 13:33
8  
@LordTydus: Totally disagree. The style and usage of C++ is not the same as in 98 thus it is not just fixing syntactic issues. –  Loki Astari Dec 26 '11 at 18:00
4  
@LordTydus If the old syntax plain and simply does not compile on modern compilers, you'll have a hard time using a book that teaches the old syntax. Note that any book that teaches the usage of iostream.h almost certainly doesn't teach e.g. namespaces either, so even after replacing iostream.h with iostream, your code won't work. If you have to google or ask for help on SO every time you want to compile an example from the book, that's not a very effective way to learn C++. –  sepp2k Dec 26 '11 at 21:47
    
@LordTydus: In general, I've found that books that use headers like that tend also to use bad practices and are riddled with errors. I've taken to collecting such books just to keep them out of circulation. –  greyfade Dec 27 '11 at 17:09
show 2 more comments

#include <iostream.h> is a sign that the book was written prior to the first C++ standard in 1998 (the standard header is iostream).

The problem is that older C++ code tends to be written in ways that are considered bad practice today. In particular,

  • The use of C-style arrays rather than container classes like std::string and std::vector.
  • The use of explicit close functions rather than RAII.

iostream.h isn't the worst thing a pre-1998 book will get wrong, but it's likely to be the first thing that a pre-1998 book will get wrong.

share|improve this answer
1  
Nailed it with your final paragraph. –  Lightness Races in Orbit Jan 11 at 17:11
add comment

Just dropping my 2 cents. I don't think there is a correlation between ".h" and the quality of a book. This is a minor syntax issue. Back in the day it was actually the correct sytnax.

Is it possible to have a great book with iostream.h? yes

Is it possible to have a terrible book with iostream? yes

I would rely on online user reviews (and my own review after reading) to judge the quality of a book.

share|improve this answer
    
Problem is, are you sure you want a book from "back in the day?" –  hugomg Dec 26 '11 at 13:39
3  
Is Lisp outdated because it's from 1958? We utilize Pythagoras's work in every modern missile system even though the math is thousands of years old. In the current C++ book market the ".h" books may well be terrible. But it is a quality of book issue, not a ".h" issue. ".h" isn't even programming logic, it's for the preprocessor. –  Lord Tydus Dec 26 '11 at 13:50
4  
but will someone learning the language for the first time know when the book is telling them something wrong? How much time and frustration will they go through before finding out that the ".h" is now incorrect? And in how many other ways is the book out of date? –  Chris Pitman Dec 26 '11 at 16:27
16  
The trouble is the usage of C++ has changed significantly since those books were written. The whole way you think and use C++ is not the same as those books will present as they do not have any of the facilities that modern C++ has. As a result you will be teaching yourself C with classes not C++. –  Loki Astari Dec 26 '11 at 17:58
2  
@Giorgio: Boring. What about ACRE. Advanced C on Ritalin with Exceptions. Acre also implies it covers a lot of ground. :-) –  Loki Astari Dec 27 '11 at 1:26
show 10 more comments

Maybe this comes a bit late but for what it's worth, on a unix/linux box do ls /usr/{local/,}include/c++/* or similar, according to your layout and paths. You could pipe to grep looking for the header in question, like:

ls /usr/{local/,}include/c++/* | grep iostream 

This entails a look-up for iostream.h as well as any other superstrings.

Or run find / -type f -name iostream 2> /dev/null | grep include or locate iostream | grep include (provided the database is current, otherwise prepend with a call to updatedb)--these, however, will print also non-system-wide includes, so please adjust appropriately. The actual C++ include path is easily found with something like:

g++ -v 2>&1| sed -rn 's/.+gxx-include[^=]+=([^ ]+).+/\1/p' # adjust iff empty

Equivalently on Windows and other machines. I guess the idea is clear--such a file as iostream.h doesn't exist in the system include path by default any longer, you still, however, can find legacy libc++ distributions with iostream.h either soft-linked to iostream or as its copy. So this is not a matter of style but rather of the circumstances. You could ship your own iostream.h with your project just make sure it's contained in the include path where your compiler looks up for the <...> headers.

share|improve this answer
    
Very practical but doesn't really address the real fundamental point. –  Lightness Races in Orbit Jan 11 at 17:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.