CyberiaPC.com Main Page




Learning C++

Understanding the Different Types of Variables/ Learn the Basics
 
 
Data Types (variables)
The Terminology
Declaring Data Types and Using the Various Operators
Rules for Naming Data Types
C++ Libraries

C++ Libraries

Libraries are files that can be used with C++ in order to operate certain functions.  They are always written at the very top.  For example, we used the cout stream object earlier, which is not recognized by C++ unless we tell it from which library it comes from.  Both cout and cin are part of the iostream.h library.  If we are using strings, we'll need to use the string.h library.  Here is our earlier program written as a complete application:

     #include<iostream.h>
     
     void main()
     {
           int userage=0;
          int myage=16;
          
          cout << "Enter your age please";
          cin >> userage;
          cout << "You are " << userage;
          cout << "I am " << myage;
          
          cout << endl; 
     }

"What the heck is void main()", you ask.  Simply put, this is a function (once again starting and ending in curly brackets) that your code must go into.  Every C++ program must have a main() function.  As for the library, it is written on the first line -outside the main() function.  If you have an old C++ compiler then you will be required to include the .h (header file).  Otherwise, you may just as well omit it.

{Go Back To C++ Lessons Page}