Introduction to C++

C++ is a powerful computer programming language that’s appropriate for technically oriented people with little or no programming experience, and for experienced

programmers to use in building substantial information systems. You’re already familiar
with the powerful tasks computers perform. 
We now introduce C++ programming, which facilitates a disciplined approach to program
design. Most of the C++ programs you’ll study in this book process information and display results. In this chapter, we present five examples that demonstrate how your programs
can display messages and obtain information from the user for processing. The first three
examples simply display messages on the screen. The next obtains two numbers from a
user, calculates their sum and displays the result. The accompanying discussion shows you
how to perform arithmetic calculations and save their results for later use. The fifth example demonstrates decision-making by showing you how to compare two numbers, then
display messages based on the comparison results. We analyze each program one line at a
time to help you ease your way into C++ programming. 



First Program in C++: Printing a Line of Text

C++ uses notations that may appear strange to nonprogrammers. We now consider a simple program that prints a line of text. This program illustrates several important
features of the C++ language.


2 // Text-printing program.
3 #include <iostream> // allows program to output data to the screen

// function main begins program execution
6 int main()
7 {
8 std::cout << "Welcome to C++!\n"; // display message
9
10
return 0; // indicate that program ended successfully
11 } // end function main

Output:
Welcome to C++!



C++ and a Typical C++ Development Environment

C++ evolved from C, which was developed by Dennis Ritchie at Bell Laboratories. C is
available for most computers and is hardware independent. With careful design, it’s possible to write C programs that are
portable to most computers.
The widespread use of C with various kinds of computers (sometimes called
hardware
platforms
) unfortunately led to many variations. A standard version of C was needed. The
American National Standards Institute (ANSI) cooperated with the International Organization for Standardization (ISO) to standardize C worldwide; the joint standard document was published in 1990 and is referred to as
ANSI/ISO 9899: 1990.
C99 is the latest ANSI standard for the C programming language. It was developed
to evolve the C language to keep pace with increasingly powerful hardware and ever more
demanding user requirements. C99 also makes C more consistent with C++. For more
information on C and C99, see our book
C How to Program, 6/e and our C Resource
Center (located at
www.deitel.com/C).
C++, an extension of C, was developed by Bjarne Stroustrup in the early 1980s at Bell
Laboratories. C++ provides a number of features that “spruce up” the C language, but
more importantly, it provides capabilities for object-oriented programming.


C++ Standard Library
C++ programs consist of pieces called classes and functions. You can program each piece
yourself, but most C++ programmers take advantage of the rich collections of classes and
functions in the
C++ Standard Library. Thus, there are really two parts to learning the
C++ “world.” The first is learning the C++ language itself; the second is learning how to
use the classes and functions in the C++ Standard Library. We discuss many of these classes
and functions. P. J. Plauger’s book,
The Standard C Library (Upper Saddle River, NJ:
Prentice Hall PTR, 1992), is a must read for programmers who need a deep understanding
of the ANSI C library functions included in C++. Many special-purpose class libraries are
supplied by independent software vendors.


Escape sequence Description
\n     Newline. Position the screen cursor to the beginning of the next line.
\t     Horizontal tab. Move the screen cursor to the next tab stop.
\r     Carriage return. Position the screen cursor to the beginning of the
        current line; do not advance to the next line.
\a     Alert. Sound the system bell.
\\     Backslash. Used to print a backslash character.
\'     Single quote. Use to print a single quote character.
\"     Double quote. Used to print a double quote character.