#include <iostream>
int main()
{
using namespace std;
//可以使用std名称空间中定义的名称,而不必使用std::前缀。
cout <<"hello world";
//把hello world发送给cout,<< 指出了信息流动的路径
cout <<endl; //start a new line;
cout << “\n”; //start a new line;
/*endl可以确保程序继续运行前刷新输出(将其立即显示在屏幕上),\n不能提供这样的保证。*/
cout <<"hello world two"<<endl;
cin.get(); //让运行窗口一直打开
cout <<"hello world two"<<endl<<"123";// more output
return 0;
// return statement 返回语句:结束该函数
/*若编译器到达int main()函数末尾时没有遇到返回语句则认为以return 0结尾,只适用于main函数,不适用于其他。*/
}
1.#include 预处理器编译指令
#include <iostream>:iostream.h中的文件将会替换这条指令。
2.int main() 函数头
int main()
可以给调用它的函数返回一个返回值,但不从调用它的函数那里获得任何信息
int main(void)
明确指出 函数不接受任何参数。C++中括号空着代表不接受参数,但在C中,括号空着代表对是否接受参数沉默
void main()
函数的返回类型是void,代表函数不返回任何值。不是标准格式
3.using namespace 编译指令
使用名称空间编译指令使iostream中的定义对程序可用。
类、函数和变量都被放置在名称空间std中。cout其实是std::cout ,endl
其实是std::endl。