一、 以下是一个简单的打印"Hello world!"语句
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
或:
#include <iostream>
//using namespace std;
int main()
{
std::cout << "Hello world!" <<std:: endl;
return 0;
}
或:
#include <iostream>
using std::cout;//表示std仅用cout 和cin;endl用法还是std::endl
using std::cin;
int main()
{
cout << "Hello world!" <<std:: endl;
return 0;
}
1、#include <iostream>;将iostream文件的内容加到程序中,io(标准输入和输出);
iostream种包含 有关输入输出语句的函数;
2、头文件命名
头文件类型 | 约定 | 示例 | 说明 |
C旧式风格 | 以.h结尾 | stdio.h;main.h | C、C++通用 |
C++旧式风格 | 以.h结尾 | iostream.h | c++可以使用 |
C++新式风格 | 没有扩展名 | iostream | C++可以使用,需要使用namespace; |
转换后的C | 加上前缀c没有扩展名 | cmath、ctype等 | C++使用 |
3、using namespace std;使用命名空间std;参考如下:
https://www.cnblogs.com/wanganyi/p/5906694.html
https://blog.youkuaiyun.com/hao534/article/details/3235853
5、endl是控制符,表示重起一行(\n);