Well, it's just out of curiosity, but why does the sleep function NOT work in a loop, or how can I make it work in a loop?
for(int i = 0; i < 5; i++) { cout << i << endl; sleep(2); }
coutIt is buffered, that is, its contents are not always written to the console immediately. Try adding cout.flush()right beforesleep(2);
cout
cout.flush()
sleep(2);
If this does not work for you, you can try this code:
#include <iostream> #include <windows.h> ... for(int i = 0; i < 5; i++) { cout << i << endl; Sleep(2000); }
, . , std:: cout - ? sleep() ( )? ? .
, , ?
cout << 1 << endl; sleep(2); cout << 2 << endl; sleep(2); // Etc.
, , std:: endl , , dave.kilian , cout , () .
std:: flush , - , ( ?) .
, - , tail -f . , .
tail -f
, , .
Dave has already given you the answer, so I wonโt touch it. However, if its pure for debugging or prototype code, you can also pass the output to std :: cout sibling, std :: cerr, which is unbuffered to start with. This means that you do not need to explicitly call flush, and you do not need to add endl to your output.
Try Sleep () instead of sleep ()
Source: https://habr.com/ru/post/1748456/More articles:ASP.NET MVC 2 EnableClientValidation: Validation Group - asp.net-mvc-2How to handle browsers where JavaScript may be disabled? - javascriptHaskell: a `show` option that does not wrap String and Char in quotation marks - pretty-printBrowser Zoom Level: Detect, Configure Using Javascript - BrowserRegister at GrailsUnitTestCase? - loggingMime file type definition - mime-typesWord Automation - SaveAs - c ++How to get two \ multicolum in LaTeX table? - latexUnexplored files to commit without intermediate tracked file changes - gitEditing LaTeX with Emacs - finding unused \ ref - emacsAll Articles