一个简单的C++程序
2012-03-07 14:59
344 查看
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.
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++》
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++》
相关文章推荐
- 一个简单封装用户命令的C++程序
- C++写的书上一个简单的电话薄程序
- C++ 容器的综合应用的一个简单实例——文本查询程序
- c++积累(1):一个简单的list容器迭代程序
- C++反汇编揭秘1 – 一个简单C++程序反汇编解析 (Rev. 3)
- 一个简单的C++程序反汇编解析
- C++反汇编揭秘1 – 一个简单C++程序反汇编解析 (Rev. 3)
- C++反汇编揭秘1 – 一个简单C++程序反汇编解析 (Rev. 3)
- 一个简单的c++加解密程序
- c++编写一个简单的数据库程序
- C++反汇编揭秘:一个简单的C++程序反汇编解析
- C/C++做的一个简单界面程序扩充,向指定窗口发送消息
- 转:C++反汇编揭秘1 一个简单的C++程序反汇编解析
- Linux下,使用C/C++一个简单的消息处理程序
- C++实践笔记(二)----实现一个简单的文本查询程序
- 用c++写一个简单的计算器程序
- C++反汇编揭秘1 一个简单的C++程序反汇编解析
- 一个简单关于学生成绩管理的C++程序代码,但是对于拷贝析构函数目前还是不知其作用何在
- VC-Logger 是一个简单易用的 C++ 程序通用日志组件
- 一个简单的程序教你区分C++中strlen与sizeof