Cout in loop doesn't print char by char as defined

后端 未结 2 350
囚心锁ツ
囚心锁ツ 2021-01-23 02:38

I\'ve recently started learning C++ at university and decided to advance a bit at home. I had the idea of making a program that, given a piece of text, would print out such text

相关标签:
2条回答
  • 2021-01-23 02:59

    You need flush output

     cout << text[i] << flush;
    

    The usleep() function returns 0 on success. On error, -1 is returned, with errno set to indicate the cause of the error.

    ERRORS EINTR Interrupted by a signal; see signal(7).

    EINVAL usec is not smaller than 1000000. (On systems where that is considered an error.)

    0 讨论(0)
  • 2021-01-23 03:00

    You need to flush the stream, otherwise it will be cached

    cout.flush();
    

    http://www.cplusplus.com/reference/ostream/basic_ostream/flush/

    0 讨论(0)
提交回复
热议问题