All this confusion over sleep or Sleep. Just use mesleep
-PreludeCode:#include <ctime> void mesleep ( long m ) { clock_t limit, c = clock(); limit = c + m; while ( limit > c ) c = clock(); }
All this confusion over sleep or Sleep. Just use mesleep
-PreludeCode:#include <ctime> void mesleep ( long m ) { clock_t limit, c = clock(); limit = c + m; while ( limit > c ) c = clock(); }
My best code is written with the delete key.
I've tried your code using "console application"...
The problem is still there.....
I don't get the cout "My display is late" until after the Sleep command...hmm..weird huh?
When I run the program, the dos screen is blank,..then some secs later, two display of "My display is late" is printed instantaneously to the screen....
Which is the master, which is the student?
>I don't get the cout "My display is late" until after the Sleep command...hmm..weird huh
Not really, buffered [edit]output[/edit] is only flushed by the system when it's convenient. If you want to flush right away then tell the compiler to do so.
cout<<"My message"<<flush;
-Prelude
My best code is written with the delete key.
Hay Prelude:
Which Japanese animation is that good looking chic next to your name from? I'm a big fan of Japanimation...my favorite is Rurouni Kenshin..or Sarmuri X (is what they call it in the US)...
Which is the master, which is the student?
>Which Japanese animation is that good looking chic next to your name from?
http://www.polykarbon.com/
I can't draw to save my life, but I can admire other people's work, right?
-Prelude
My best code is written with the delete key.
AH...Prelude's THE MAN!
That flush command was what I was looking for ...
Now cout prints to the screen before going to sleep and my problem is solved!
btw,..I have another question...
If i was to just print "hello world" on a "Win32" application..what files do I have to include??
Can you give me the exact code that I'll need...because i'm getting errors when I use the code for "console application" that would print "hello world"..
Which is the master, which is the student?
One more question if you don't mind
Let say you've started a project on "console application",...can you change it to win32 application later on?? Is there any reason why someone would want to change it and would the code be compatible??
Curiousity saved the cat...
Last edited by Jez_Master; 04-07-2002 at 08:22 PM.
Which is the master, which is the student?
>Can you give me the exact code that I'll need
It depends on how complex you want the code to be. If all you want to do is print "Hello, World!" then it's almost as simple as a console app.
If you want to create a window and print something in the client area then it is considerably more difficult.Code:#include <windows.h> int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow) { MessageBox (NULL, "Hello, World!", "Hello", MB_OK); return 0; }
>can you change it to win32 application later on??Code:#include <windows.h> const char g_szClassName[] = "window one"; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch(msg) { case WM_PAINT: hdc = BeginPaint ( hwnd, &ps ); GetClientRect ( hwnd, &rect ); DrawText ( hdc, TEXT ( "Hello, World!" ), -1, &rect, DT_SINGLELINE ); EndPaint ( hwnd, &ps ); break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG Msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_szClassName, "Some Title", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }
Perhaps in the .NET framework, but as far as I know you have to keep Win32 applications and console applications separate or there will be linker errors.
-Prelude
My best code is written with the delete key.
ummmmm, tell me if this doesn't workCode:main() { //this should work cout << "This should show this then sleep << endl; Sleep(1000); cout << "It waited, yay!" << endl; }
it should i think
Yes, those code works...
but my code calls a function in main,..and that's where all the timing problem come into play...
like prelude suggested, using "flush" works like a charm
Which is the master, which is the student?
when you use cout or whatver, its put into stdout(the buffer) so when you fflush(stdout), the buffer is "flushed". if you use C, you can also flush the file buffer.