to .h or not to .h

Submitted on: 1/3/2015 5:31:00 AM
By: James Turk (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 396
     An article explaining why #include <iostream.h> is wrong in the C++ Standard.

				Many people still submit code which includes a line like this: 

#include <iostream.h>

and so I would like to explain how this is wrong, this is an old old header, and should not be used in modern code... Right now it does not cause problems, but there is a possibility that in future revisions of the C++ standard that the .h headers will be completely obsolete.

<iostream.h> includes the old style iostream classes, and originally was required. This is obsolete according to the new c++ standard, which specifies that .h should not be used on standard header files. If you are in need of the old C headers you should use these:

etc.. basically you place a c in front of the old name and remove the .h. So far this syntax for leaving of the .h only causes conflict in one area, the STL string class. String manipulations (using char*-null-terminated strings) are contained in <string.h>, and <string> includes the nice STL string class which is much easier than using char* strings, so in C++ string.h should be refered to as <cstring> to avoid confusion.

A word of caution: when using the .h-less header files most compilers require an extra line after the final include statment: using namespace std; This namespace will allow you to access all of the members of the .h-less headers properly and easily (so to use cout and cin you dont have to type std::cout, or std::cin, etc.)

Other 1 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.