注册 登录
编程论坛 C++教室

新手求教,std::cout << std::endl;的作用。

Majery 发布于 2018-05-13 16:41, 1991 次点击
刚开始学C++,做第五版后面的习题,题目要求:使用递减运算符在循环中按递减序打印出10到0之间的整数。

#include <iostream>
int main()
{
    int i = 10;
    while (i > 0) {
        std::cout << i << " ";
        --i;
    }
    std::cout << std::endl;
    return 0;
}

答案上有红色的那行,放在那里的作用是啥?不太懂,是为了单纯的清缓存么?
3 回复
#2
rjsp2018-05-13 21:56
http://zh.
#3
Jonny02012018-05-13 22:14
endl的作用是换行顺便清理流内的缓存,将缓冲区的内容印刷到设备上
你暂时理解成换行就对了
后面继续学下去,学到 IO 库再探这部分估计就会理解
#4
cstdio2019-05-30 12:26
std::cout<<std::endl;/*等同于*/printf("\n");
1