这是一段代码
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
and
#include <iostream>
using namespace std;
int main()
{
cout << "Hello word! " << '\n';
return 0;
}
and
#include <iostream>
using namespace std;
int main()
{
cout << "Hello word! " << '\n';
return 0;
}
输出结果都是一样的;
区别
endl确保程序继续运行前刷新输出,也就是说将其立马显示在屏幕上;
而且,endl是在头文件iostream中定义的,并且在命名空间std中。
\n 有可能在输入信息后才会出现提示,\n被称为转义字符