C++换行符-----'\n'&endl

这是一段代码

   #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被称为转义字符

猜你喜欢

转载自blog.csdn.net/AsukaShin/article/details/85337284