-
Sleep
When I run this code:
Code:
#include <windows.h>
#include <iostream.h>
int sleep (int sleep_for)
{
int start=timeGetTime();
BOOL sleeping=TRUE;
while (sleeping)
{
int current=timeGetTime();
if (current-sleep_for>=start)
break;
}
return 0;
}
int main()
{
cout<<"YAY";
sleep(2000);
return 0;
}
it sleep for the right amount of time, but it doesn't display the text. Why isn't the text being displayed? Thanks in advance.
-
> cout<<"YAY";
Try:
cout<<"YAY" << flush;
-
Thanks, that works. But why should it work? I've never seen flush before.
-
On some compilers, the output isn't sent to the console until a newline (endl) is written, or maybe the buffer fills up. So you have to flush the stream to force it to be written to the console. I use a borland compiler, and the flush usually isn't needed.
-
I use VC++ .NET and flush usually isn't need either
-
what type of project is it? i tired win32 app and console app it won't compile an exe file >_<
-
Yeah, you need to have the winmm.lib included. Right click on the project in solution explorer. Go to properties and choose linker. It's the second thing down in the linker folder called Input. Go to the first thing on the input tab where it says additional dependecies and type "winmm.lib" lose the quotes though. Then go to the bottom and hit apply.
PS- It's a console app
-
i really dislike to be such a pain, whats solution explorer?
I am useing Visual C++ 5.0/97 if it helps any
-
oh, I was using .NET. In your case, I think you need to go to Project>Properties (in the menu at top)
-