Buffered and unbuffered stream

前端 未结 5 685
迷失自我
迷失自我 2020-12-10 00:07

In case of buffered stream it said in a book that it wait until the buffer is full to write back to the monitor. For example:

cout << \"hi\"; 
<         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-10 00:44

    You can check out the differences yourself with a small app.

    #include 
    int main() {
        std::cout<<"Start";
        //std::cout<<"Start"<

    Try out the difference of the two "Start" statments, then change to cerr. The difference you notice is due to buffering.

    The for-statement takes about 2 seconds on my rig, you might need to tweak the i < condition on yours.

提交回复
热议问题