June 10th, 2005, 03:24 PM
C++ General: What are C++ Headers?
Q: What are traditional C++ (pre-standard) headers?
A: The traditional C++ (pre-standard) headers define classes, values, macros, and functions in headers that have *.h extension. This includes non-standard STL headers with *.h extension (iostream.h, fstream.h, vector.h, etc.) and C headers with *.h extension (stdlib.h, stdio.h, etc.). Pre-standard headers have all the code in the global namespace.
Q: What are C++ standard headers?
A: C++ standard headers are those headers that are specified by the C++ standard.
Q: How do I recognize the C++ standard headers?
A: The naming scheme for these files were specified based on the naming scheme of the traditional header files, but without the ending '.h'. For example, 'fstream.h' becomes 'fstream', 'memory.h' becomes 'memory' and so on.
Q: What about 'iostream.h'?
A: The header iostream.h has never been part of the official C++ standard, which means any compiler that provides iostream.h, can do what ever it wants with it, and the compiler would still be considered compliant with the C++ standard. However, the C+ standard specifies the existence of a header within the input/output library.
Q: What about the traditional ANSI C standard header files?
A: The traditional ANSI C standard header files are prefixed with the letter 'c'. Thus 'stdio.h' has become 'cstdio', 'stdlib.h' is called 'cstdlib', 'math.h' is called 'cmath', 'time.h' is called 'ctime' and so on. This is the complete list:
- <assert.h> - <cassert>
- <ctype.h> - <cctype>
- <errno.h> - <cerrno>
- <float.h> - <cfloat>
- <iso646.h> - <ciso646>
- <limits.h> - <climits>
- <locale.h> - <clocale>
- <math.h> - <cmath>
- <setjmp.h> - <csetjmp>
- <signal.h> - <csignal>
- <stdarg.h> - <cstdarg>
- <stddef.h> - <cstddef>
- <stdio.h> - <cstdio>
- <stdlib.h> - <cstdlib>
- <string.h> - <cstring>
- <time.h> - <ctime>
- <wchar.h> - <cwchar>
- <wtype.h> - <cwtype>
Q: Which are the C++ standard headers?
A: Grouped on library category, here they are:
- Language support:
- Types: <cstddef>
- Implementation properties: <limits>, <climits>, <cfloat>
- Start and termination: <cstdlib>
- Dynamic memory management: <new>
- Type identification: <typeinfo>
- Exception handling: <exception>
- Other runtime support: <cstdarg>, <csetjmp>, <ctime>, <csignal>, <cstdlib>
- Exception classes: <stdexcept>
- Assertions: <cassert>
- Error numbers: <cerrno>
- General utilities:
- Utility components: <utility>
- Function objects: <functional>
- Memory: <memory>
- Date and time: <ctime>
- Character traits: <string>
- String classes: <string>
- Null-terminated sequence utilities: <cctype>, <cwctype>, <cstring>, <cwchar>, <cstdlib>
- Locales: <locale>
- C library locales: <clocale>
- Sequences: <deque>, <list>, <queue>, <stack>, <vector>
- Associative containers: <map>, <set>
- Bitset: <bitset>
- Iterators: <iterator>
- Non-modifying sequence operations: <algorithm>
- C library algorithms: <cstdlib>
- Complex numbers: <complex>
- Numeric arrays: <valarray>
- Generalized numeric operations: <numeric>
- C library: <cmath>, <cstdlib>
- Forward declarations: <iosfwd>
- Standard iostream objects: <iostream>
- Iostreams base classes: <ios>
- Stream buffers: <streambuf>
- Formatting and manipulators: <istream>, <ostream>, <iomanip>
- String streams: <sstream>, <cstdlib>
- File streams: <fstream>, <cstdio>, <cwchar>
Q: Could I still use the extension version of the C headers (stdlib.h, stdio.h, etc.)?
A: All compliant C++ compilers support the 18 deprecated C header files with the *.h extension (stdlib.h, stdio.h, etc.). The *.h extension C header files are in the global namespace. Code using the extension version of the C headers is still considered portable, but it might not be portable with a future version of the standard. However, itís unlikely that these headers will ever be completely removed from the official standard.
Q: Could I still use the non-standard *.h extension version of the STL headers (iostream.h, fstream.h, vector.h, etc.)?
A: The extension versions of the STL headers have never been part of the official C++ standard. Most compilers support the non-standard STL headers, and some obsolete compilers (like Turbo C++) only support the non-standard version of the STL headers. More modern compliant compilers like VC++ 7.1, do not support these files at all. Unless an obsolete compiler is being used, all new code should be developed using the extension-less version of the STL headers (<iostream>, <fstream>, <vector>, etc.). Code using *.h extension version of the STL headers is not considered portable.
Credits: This FAQ is the result of a joint effort of Cilu, Andreas Masur and Axter.
Last edited by cilu; September 17th, 2005 at 09:10 AM.
July 30th, 2005, 09:18 AM
Re: C++ General: What are C++ Headers?
On certain compilers, for example, you may find 'iostream' as well as 'iostream.h'. As pointed out above including 'iostream' keeps the members in the std namespace whereas usage of 'iostream.h' adds up the members into the global namespace. This may lead to ambiguities that the namespaces were designed to avoid. This is another small reason in addition to others mentioned above for not including the '.h' extension headers.
Last edited by Andreas Masur; September 4th, 2005 at 10:29 AM.
Click Here to Expand Forum to Full Width