Using the sleep function

This is a discussion on Using the sleep function within the C++ Programming forums, part of the General Programming Boards category; I'm trying to use the sleep function for a program that simulates a traffic light. But when i use the ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    2

    Using the sleep function

    I'm trying to use the sleep function for a program that simulates a traffic light. But when i use the function it delays the start of the program not between where i have printed light green and light yellow to the screen where i want it.

    I have placed it between the two cout statements and it still delays the beginning of the program which makes no sense.

    Anyone got any ideas?

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Post your complete code. Don't forget to use code tags (instructions on how to use them are at the top of the C++ board.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Perhaps you need to flush your first console output. Otherwise the system may buffer it:
    Code:
    cout << "Light green." << flush;
    Or you can add a endl which will output a newline and flush the buffer:
    Code:
    cout << "Light green." << endl;

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    2

    Thanx

    Thanks Swoopy that worked all it needed was a flush. Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21