Thread: Question

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    51

    Question

    Hi,

    when you have,

    cout<<"WASSUP";
    Sleep(1000);

    my question is: Is there a way to purge the cout buffer because right now, my program is going to sleep before printing out "WASSUP" to the screen...

    thx
    Which is the master, which is the student?

  2. #2
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    this works fine, what do the parameters mean though? a 100 seconds?

    Code:
    #include <iostream.h>
    #include <dos.h>
    
    main()
    {
    	cout<<"falling asleep"<<endl;//notes
    	sleep(100);
    	cout<<"waking up";
    	return(0);
    }

  3. #3
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    sleeps parameters are milliseconds, so 1000 is 1 second.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  4. #4
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    well, i compiled, exed, waited, waited, waited, went to the bathroom, chated with my wife, brought the groceries in from the car, and it was still running. when i set it to 100 it took about 30 seconds? what's the deal?

  5. #5
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    waited, waited, waited, went to the bathroom, chated with my wife, brought the groceries in from the car
    !!You did all that in 100 seconds!!

    sleep(1000) runs for 1 second for me.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    Hi,

    When you do a "cout"..does it ouputs to the screen immediately or is it inserted into some buffer and it outputs to the screen what that buffer is full?

    I'm having problem with the timing of cout...seems like whenever cout finally prints something on the screen, it's a big chunk of data...(I'm guessing cout prints to the screen when the buffer's full which explains the problem i'm having ...)
    Which is the master, which is the student?

  7. #7
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    c_coder, bcc55 says i have an outdated header, could that be why it takes so long?

    btw, i have the abilty to manipulate time in such a way that what takes a normal person a few minutes, takes me only 100 seconds

  8. #8
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    bcc55 says i have an outdated header, could that be why it takes so long?
    Maybe, I'm using msvc so I may have a different sleep function to you anyway.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  9. #9
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    When you do a "cout"..does it ouputs to the screen immediately or is it inserted into some buffer and it outputs to the screen what that buffer is full?
    Well I suspect that it is sent to the screen via a buffer, however it should be displayed immediatly, post a program that dosen't work properly.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  10. #10
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    jez, copy mine into your editor and tell us what happens

  11. #11
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    from what i know -

    Sleep with "S" is in milisecs
    sleep with "s" is seconds

    this is probablt compiler specific, i think borland uses "s"
    -

  12. #12
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    Blight2:

    I tried your code and it works fine..

    cout displays onto the screen before the wait command...
    I wonder why my code is doing the display late..

    In my code, I have the main function call a display function (cout << "My display is late..";..

    void display() {


    int main() {
    display();
    continue;
    main (); //Here I call main again, is this a good
    //programming practice?
    }
    Which is the master, which is the student?

  13. #13
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    Sorry about the above post, I accidently hit TAB and then hit the SPACE BAR...

    Blight2:

    I tried your code and it works fine..

    cout displays onto the screen before the wait command...
    I wonder why my code is doing the display late..

    In my code, I have the main function call a display function

    void display() {
    cout << "My display is late";
    while(!kbhit())
    { // do nothing }
    }

    int main() {
    display();
    continue;
    main (); //Here I call main again, is this a good
    //programming practice?
    }


    My problem is "My display is late" doesn't outputs to the screen until I hit the keyboard....which is not good
    Which is the master, which is the student?

  14. #14
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    wow, that's all mixed up to me. try this:

    Code:
    #include <iostream.h>
    #include <dos.h>
    
    void display();
    
    main()
    { 
    	 
    	display();  
    	sleep(10);
    	display();
    	return(0);
    }
    
    void display ()
    {cout << "My display is late";
    }
    "Sleep" doesn't seem to work in borland (at least dos.h) is there another?

  15. #15
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    Should I make a console application or a win32 application for the above code??
    Which is the master, which is the student?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM