cpp header files

C++ header files

We have used the following #include directive with headerfile in the program

#include< iostream >

This directive cause the preprocessor to add the contents of the iostream file to the program. It contains the declarations to the identifiers cout and the operator << some old version of C++ use a header file called iostream.h. This is one of the change introduced by ANSI C++(we sould use iostream.h if the compiler does not support ANSI C++ features)

The header file iostream should be included at the beginning of all programs that use input/output statements.

Note that the naming conventions for header files may very. some implementations use iostream.hpp yet others iostream.hxx. we must include appropriate header files depending on the contents of the program and implementation.

In the below table show the header files that may be needed in C++ program. The header files with extension .h and also show new version of header files should be used with the ANSI standard compilers

Headerfile Content and purpose New Version
< assert.h > Contains macros and information for adding diagnostics that aid program debugging < cassert >
< ctype.h > Contains function prototypes for functions that test characters for certain properties, and function prototypes for functions that can be used to convert to lowercase letters to uppercase letters and vice versa < cctype >
< float.h > contains the floating point size limits of the system < cfloat >
< limits.h > contains the integral size limits of the system < climits >
< math.h > Contains function prototypes for math library function < cmath >
< stdio.h > contains function prototype for the standard input/output library functions and information used by them < cstdio >
< stdlib.h > contains function prototypes for conversion of number to text,text to number, memory allocation, random number, and and various other utility functions < cstdlib>
< string.h > contains function prototypes for c style string processing functions < cstring >
< time.h > contains function prototypes and types of manipulation the time and date
< iostream.h > contains function prototypes for the standard input/output < iostream >
< iomanip.h > contains function prototype for the stream manipulators that enable formatting of streams of data < iomanip >
< fstream.h > contains function prototypes for functions that perform input from files on disk and output to files on disk fstream

New header files included in ANSI C++

Headerfile Contents and purpose
< utility > Contains classes and functions that are used by many standard library header files
< vector >< list >< deque >< queue > < set >< map >< stack >< bitset > The header files contains classes that implement the standard library containers. containers store data during a program execution.
< functional > contains classes and functions used by algorithm of the standard library
< iterator > contains classes for manipulating data in the standard library containers contains class and functions used by the standard library to allocate memory to the standard library containers
< algorithm > contains function for manipulating data in the standard library container
< exception > < stdexcept > These header files contains classes that are used for exception on handling
< string > contains the definition of class string from the standard library discuss in the next pages
< string.h > contains function prototypes for c style string processing functions
< sstream > contains function prototypes for functions that perform input from strings in memory and output to string in memory
< local > contains classes and functions normally used by stream processing to process data in the natural form for different languages
< limits > contains a class for defining the numerical data type limits on each computer platform
< typeinfo > contains classes for runtime type identification(determine data types at execution)

Namespace

Namespace is new concept introduction by the ANSI C++ standards committee. This defines a scope for the identifiers that are used in a program. For using the identifiers defined in the namespace scope we must include the using directive like

using namespace std;

Here std is the namespace where ANSI C++ standard class libraries are defined . all ANSI C++ programs must include this directive. This wi;; bring all the identifiers defined in std to the current global scope. using and namespace are the new keywords of C++ Namespaces are learn in the next pages

Return type of main()

main()
{
…..
……
…..
}

#include<iostream> // include header file
using namespace std;
int main()
{
int age;
cout << "Enter your age:";
cin >> age;
cout << "\nYour age " << age;
return 0;
}

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise