usleep() problem
Apr 24, 2010 at 7:14am UTC
Hi all!!
I want to make loading effect in c++. When I use this code, program works, but I want cout in one line.
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{ int i;
for (i = 0; i < 50; i++)
{ usleep(100000);
cout <<"|" << endl;
}
return 0;
}
When I use this code, cout is in one line, but the program doesn't do what I wanted to do. He waits about 50*100000 and then prints 50 times |.
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{ int i;
for (i = 0; i < 50; i++)
{ usleep(100000);
cout <<"|" ;
}
return 0;
}
Please help!!!
Apr 24, 2010 at 7:53am UTC
Try
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{ int i;
for (i = 0; i < 50; i++)
{ usleep(100000);
cout <<"|" << flush;
}
return 0;
}
Apr 24, 2010 at 7:57am UTC
Oh...
Thank you very much...
Can You tell me what means flush??
Apr 24, 2010 at 8:07am UTC
Topic archived. No new replies allowed.