I want to simulate the typing of text (as if someone was typing it on the screen) while printing a string. Simply put, print a character, wait for a short while, and then print the next character and so on.
void type(char* str)
{
if(*str==0)
{
return;
}
else
{
cout << (char)(*str);
usleep(200000); // should pause for 0.2 seconds after every print
type(str+1);
}
}
So, technically type("hello world") should print each character of "hello world" with a 0.2 second gap. Instead, this waits for n*(0.2) seconds (n is the length of the string) at the beginning, and then prints the whole string. It does not show this animation effect.
I tried looping, but this problem still persists. So, what's wrong with this code?
I'm using ubuntu 16.04 LTS. GCC v5.3.1 20160413.
Thanks.