ends,flush,endl 用法区别

ends函数 终止字符串
flush函数 刷新缓冲区
endl函数 终止一行并刷新缓冲区

#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

猜你喜欢

转载自blog.csdn.net/f110300641/article/details/83818306