A Simple Program:
Printing a Line of Text
- Comments
- Document Programs
- Improve program readability
- Ignored by compiler
- Single-line comment
- Begin with //
- Multiple-line comment
- Everything between /* and */ is ignored
- Preprocessor directives
- Processed by preprocessor before compiling
- Begin with #
- #include
- #define
C++ Preprocessor
- C++ Compilers automatically invoke a preprocessor that takes care of #include statements and some other special directives.
- You don't need to do anything special to run the preprocessor - it happens automatically.
The Preprocessor
- Lines that start with the character '#' are special instructions to a preprocessor.
- The preprocessor can replace the line with something else:
- include: replaced with contents of a file
- Other directives tell the preprocessor to look for patterns in the program and do some fancy processing.
Preprocessing
- C++ Program
- C++ Preprocessor
- Temporary file (C++ program)
- C++ Compiler
- Executable Program
![]() |
Click on image to enlarge it |
Output of above program:
![]() |
Click on image to enlarge it |
The program was written in Microsoft Visual C++ 6.0
You can use any compiler which you find easy to use but I suggest you to use Microsoft Visual C++ 6.0 or Borland in the beginning if you want to be a good programmer.
- Output stream object
- cout
- "Connected" to screen
- <<
- Stream insertion operator
- Value to right (right operand) inserted into output stream
- Namespace
- using namespace std; specifies that we are using objects from "namespace" std
- Escape character and escape sequences
- \ is called the "Escape Character"
- Indicates "special" character output
![]() |
Click on image to enlarge it |
(To be continued)