Why do std::cout and printf() not print between usleep() delays? -
i have program supposed print "hello, world!" in scrolling text. using unistd.h library usleep() function, , i'm using std::cout print characters standard output:
#include <iostream> #include <stdio.h> #include <unistd.h> char hello[13]={'h','e','l','l','o',',',' ','w','o','r','l','d'}; int main (){ for(int i=0; i<14; i++){ std::cout<<hello[i]; //it prints entire string after usleep(100000); //100000 ms, should print char after } //every 100 ms. }
you might need flush output stream.
Comments
Post a Comment