第一个C++函数--学习笔记

第一个C++函数

#include <iostream>    //a preprocessor directive
int main()             // function header
{                      // start of function body , function:函数
   using namespace std;   // make a definitions visible
   cout << "Come up and C++ me some time.";//
message,come up 走近C,
    cout << endl;                           // start a new line
   cout << "You wont regret it! "<< endl;   //more output
   return 0;                                //terminate main()
}                      //end of function body

输出结果:

Come up and C++ me some time.
You wont regret it!

#include 预处理器编译指令 // 单行注释标志,/* */, 多行注释

#include <iostream> ;把 iostream 文件放入函数中,iostream 文件包含cout ;cin 等输入输出命令,调用cout标准输出,cin标准输入命令,程序必须包含 iostream 文件。io 表示输入和输出,stream ,表示 流,如流动的意思。

int main() 函数头;c++中必须有一个主函数main(),程序执行时,通常从main()开始

return 0 ; 表示main() 函数的结束

{ } ;表示函数体。

;C++函数中,每句命令结束时都用分号表示。

using namespace std; 使用标准命名空间,std : standard 标准 。可省略,但需在cout/cin前加 using std :: cout ;

endl ;控制符,表示重起一行,end line,在iostream文件中定义,且位于名称空间 std 中。同换行符 “/n” 功能相等,但endl 在程序运行前刷新输出。

<< :插入运算符,把字符串“ Come up and C++ me some time.”插入输出流中。

猜你喜欢

转载自www.cnblogs.com/mayibanjia/p/12384929.html