永远的第一个程序“hello world”
#inculde <stdio.h>
其中
C语言本身不提供输入输出语句,需要有头文件嵌入源文件中使得下面语句得以执行。
#include是在程序编译之前要进行处理的的内容,因此也称为预处理命令,作用是调动库函数。
include是一个计算机专业术语,指C/C++中包含头文件命令,用于将指定头文件嵌入源文件中。
而stdio.h则是C语言编译系统提供的一个文件名,stdio是“standard input & output”的缩写,即有关标准输入输出的信息。
int main()
int代表一种数据类型,表示整数类型,常用来取一个数中的整数部分
main()即一种程序执行的入口 也可写作int main(void)
return 0; 表示函数正常退出 结束循环 提供一个返回值给调用者
#include <stdio.h>
int main()
{
printf("hello world");
return 0;
}
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
return 0;
}
通过观察不同代码同样结果的hello world,发现c++的#include <stdio.h>以及#include <iostream.h>,区别如下https://blog.csdn.net/weixin_62626298/article/details/124325868
在通过对这几种对比include<stdio.h> 和include<iostream.h>区别为:来源不同、命名空间不同、移植不同
include<stdio.h> 是C标准库里面的函数库,对应的基本都是标准输入输出等C语言常用库的定义。
include<iostream.h>是C++标准库的函数库,对应的基本上是C++的输入输出相关库定义。
开发C程序用stdio而C++用stdio/iostream 都可以,但是一般来说最好是用iostream。
#include<stdio.h>是C的标准库,用scanf和printf;#include< iostream>用cin和cout。(cout:标准输出;cin:标准输入)
< iostream>和<iostream.h>的区别
<iostream.h>继承C语言的标准库文件(未引入namespace),所以其输出可直接引用cout<<x;
而< iostream>却不能够这样去使用,因为C++中为了避免名字定义冲突,特别引入了“名字空间的定义”,即namespace。
本质上来说是c与c++的区别 后者如若要输出需要提前引用名字空间,输出时即std::cout<<x;
引用方法一般using namespace std
using namespace std指调用命名空间std内定义的所有标识符。
using namespace std;
cout<<x;