C++中ends,flush,endl 用法区别

- ends: 终止字符串

- endl: 终止一行 并刷新缓冲区

- flush: 刷新缓冲区的数据

#include <iostream>

int main()
{
    using namespace std;
    cout << "a" ;
    cout << "b" <<ends;
    cout << "c" <<endl;
    cout << "e" << flush;
    cout << "f" << flush;
    cout << "g" ;
    cout << "h" <<ends;
    cout << "i" << flush;
    cout << "j" <<endl;
    return 0;
}

结果
ab c
efgh ij
上一篇:随笔


下一篇:Java学习笔记41——匿名对象