C++ evolved form the programming language C, at the same time, C++ has incorporated many features that were not part of C, such as:
1)symbolic constants,
2)in-line functio substitution,
3)reference types,
4)parametric polymorphism through templates,
5)exceptions.
As a result, C++ has grown to be a complex programming language.
Lines 1 and Line 2 input the two header files, "cstdlib" and "iostream",Header files are used to provide special declarations and definitions, which are of use to the program.
"cstdlib":provides some standard system definitions
"iostream": provides definitions needed for input and output.
The initial entry point for C++ programs is the function main.
The statement "int main()" on line 4 declares main to be a function that takes no arguments and returns
an integer result.
The function body is given within curly braces({...}), which start on line 4 and end on line 11.
The program terminates when the return statement on line 10 is executed.
By convention, the function main returns the value zero to indicate success and returns a nonzero value
to indicate failure. The include file cstdlib defines the constant EXIT_SUCCESS to be 0.Thus, the return statement
on line 10 returns 0, indicating a sucessful termination.
1)symbolic constants,
2)in-line functio substitution,
3)reference types,
4)parametric polymorphism through templates,
5)exceptions.
As a result, C++ has grown to be a complex programming language.
A simple C++ program
#include <cstdlib>
#include <iostream>
int main()
{
int x, y;
std::cout << "Please enter two numbers: ";
std::cin >> x >> y;
int sum = x + y;
std::cout << "Their sum is: " << sum << std::endl;
return EXIT_SUCCESS;
}
Lines 1 and Line 2 input the two header files, "cstdlib" and "iostream",Header files are used to provide special declarations and definitions, which are of use to the program.
"cstdlib":provides some standard system definitions
"iostream": provides definitions needed for input and output.
The initial entry point for C++ programs is the function main.
The statement "int main()" on line 4 declares main to be a function that takes no arguments and returns
an integer result.
The function body is given within curly braces({...}), which start on line 4 and end on line 11.
The program terminates when the return statement on line 10 is executed.
By convention, the function main returns the value zero to indicate success and returns a nonzero value
to indicate failure. The include file cstdlib defines the constant EXIT_SUCCESS to be 0.Thus, the return statement
on line 10 returns 0, indicating a sucessful termination.
come from the book 《Data structures and algorithms in C++》

被折叠的 条评论
为什么被折叠?



