Advertisement

Clarification on #include <x.h>/<x> and namespaces

Started by June 18, 2002 02:21 PM
7 comments, last by pizza box 22 years, 6 months ago
I''ve been programming for a while from slightly older books, and all of them use the .h header postfix when using includes. I have not run into any problems relating to this issue that I know of. What is the difference between using no postfix to using .h? (ex. #include <iostream> / #include <iostream.h>. Also, can I drop the .h on all header files, such as or ? And would it require another namespace for any non-standard C++ header files? A lot of questions, but I want to change my code without having any significant errors.
The extension is required for most headers, but it is incorrect to add an extension to the name of a standard C++ header. Some of standard headers are: utility, list, vector, deque, queue, stack, map, set, bitset, functional, algorithm, string, exception, stdexcept, iostream, fstream, locale, sstream, limits and typeinfo.

Advertisement
<x.h> and <x> are two different files. They may or may not have equivalent content. For example:

  // example <cstdlib>namespace std {#include <stdlib.h>}// <stdlib.h>void exit();  

In this example, &ltcstdlib> just includes the old header in std namespace. If you take iostreams, however, then <xstream.h> and <xstream> provide two completely different implementations. Certain headers exist only in <header> version, such as &ltvector>, and others exist only in <header.h> versions, such as <windows.h>.
---visit #directxdev on afternet <- not just for directx, despite the name
quote: Original post by Sethius
I''ve been programming for a while from slightly older books, and all of them use the .h header postfix when using includes. I have not run into any problems relating to this issue that I know of. What is the difference between using no postfix to using .h? (ex. #include <iostream> / #include <iostream.h>. Also, can I drop the .h on all header files, such as <windows.h> or <ddraw.h>? And would it require another namespace for any non-standard C++ header files? A lot of questions, but I want to change my code without having any significant errors.


My experiance has been it depends on the compiler. I''ve used a few compilers that it didn''t matter and others that required it.
quote: Original post by IndirectX
&lt

You must end it with a semicolon, &lt;, or it won''t work in most browsers.

Thanks for the help.
Advertisement
Dont know if you guys noticed... But if you use its takes up less room intstead of . Just checking.



Stick
Just FYI:

If you use #include <iostream.h> in VC .NET, it''ll scream at you that "old iostreams are depricated" and VC 8 will not support them.

IMHO, if there''s an extensionless version of the header, use it. My $0.02.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
i support your choice of trying to get into the present by learning the standard.

just like dude said above me, soon the old stuff will be phased out.

This topic is closed to new replies.

Advertisement