Connecting Tech Pros Worldwide Help | Site Map

time delaying?

  #1  
Old July 23rd, 2005, 12:31 AM
Sargo
Guest
 
Posts: n/a
Hey all,

Im fairly new with C++ and i havent been able to find an answer anywhere
else so far, so I'm asking here.

I'm looking for a way to do a time delay. What I mean by this is where the
code outputs a line to the screen (console app) and then waits say... 5
seconds and then prints out the next line.

Is this possible? Thanks in advance


  #2  
Old July 23rd, 2005, 12:31 AM
Sargo
Guest
 
Posts: n/a

re: time delaying?



"Sargo" <sargo001@chartermi.net> wrote in message
news:sd_Dd.53436$lr1.15499@fe05.lga...[color=blue]
> Hey all,
>
> Im fairly new with C++ and i havent been able to find an answer anywhere
> else so far, so I'm asking here.
>
> I'm looking for a way to do a time delay. What I mean by this is where[/color]
the[color=blue]
> code outputs a line to the screen (console app) and then waits say... 5
> seconds and then prints out the next line.
>
> Is this possible? Thanks in advance
>
>[/color]

I should also mention that this delay should delay only the function that
requires it and not pausing the entire program itself. I forgot to mention
that. Sorry.


  #3  
Old July 23rd, 2005, 12:31 AM
ajk
Guest
 
Posts: n/a

re: time delaying?


On Sat, 8 Jan 2005 18:31:43 -0500, "Sargo" <sargo001@chartermi.net>
wrote:
[color=blue]
>Hey all,
>
>Im fairly new with C++ and i havent been able to find an answer anywhere
>else so far, so I'm asking here.
>
>I'm looking for a way to do a time delay. What I mean by this is where the
>code outputs a line to the screen (console app) and then waits say... 5
>seconds and then prints out the next line.
>
>Is this possible? Thanks in advance
>[/color]

yes it is possible but is not a part of the C++ language - if you want
to have more general help I would suggest a forum like
microsoft.public.vc.language.

now to your question: in windows you can use the Sleep function
to suspend execution of the current thread.

// void Sleep( DWORD milliseconds );

Sleep( 5000 ); // wait 5 seconds

hth/ajk
--
"Those are my principles. If you don't like them I have others."
Groucho Marx.
  #4  
Old July 23rd, 2005, 12:31 AM
Victor Bazarov
Guest
 
Posts: n/a

re: time delaying?


"Sargo" <sargo001@chartermi.net> wrote...[color=blue]
> Im fairly new with C++ and i havent been able to find an answer anywhere
> else so far, so I'm asking here.
>
> I'm looking for a way to do a time delay. What I mean by this is where
> the
> code outputs a line to the screen (console app) and then waits say... 5
> seconds and then prints out the next line.
>
> Is this possible? Thanks in advance[/color]

Yes, something like

cout << "a line" << endl;
time_t t1 = time(0), t2;
do
t2 = time(0);
while (_difference_in_seconds_(t1, t2) < 5);
cout << "the next line" << endl;

Now, you will somehow have to implement _difference_in_seconds_
function, RTFM about 'localtime' function.

If you don't mind to be OS-specific, you can probably use some kind
of OS-specific way to introduce a delay. You will have to ask in
a newsgroup dedicated to your OS (whatever that is).

Victor


  #5  
Old July 23rd, 2005, 12:32 AM
Jerry Coffin
Guest
 
Posts: n/a

re: time delaying?


[ ... ]
[color=blue]
> while (_difference_in_seconds_(t1, t2) < 5);
> cout << "the next line" << endl;
>
> Now, you will somehow have to implement _difference_in_seconds_
> function, RTFM about 'localtime' function.[/color]

To me, it seems like difftime would be considerably more useful than
localtime.

--
Later,
Jerry.

The universe is a figment of its own imagination.

  #6  
Old July 23rd, 2005, 12:32 AM
Victor Bazarov
Guest
 
Posts: n/a

re: time delaying?


"Sargo" <sargo001@chartermi.net> wrote...[color=blue]
>
> "Sargo" <sargo001@chartermi.net> wrote in message
> news:sd_Dd.53436$lr1.15499@fe05.lga...[color=green]
>> Hey all,
>>
>> Im fairly new with C++ and i havent been able to find an answer anywhere
>> else so far, so I'm asking here.
>>
>> I'm looking for a way to do a time delay. What I mean by this is where[/color]
> the[color=green]
>> code outputs a line to the screen (console app) and then waits say... 5
>> seconds and then prints out the next line.
>>
>> Is this possible? Thanks in advance
>>
>>[/color]
>
> I should also mention that this delay should delay only the function that
> requires it and not pausing the entire program itself. I forgot to
> mention
> that. Sorry.[/color]

C++ virtual machine works in such way that the program is the _single_
sequence of statements executed _strictly_ in order. So, when it is time
to _execute_ your pause the whole virtual machine is going to delay any
further execution.

If you would like to discuss _multithreading_, try comp.programming.threads
or the newsgroup for your OS.

Victor


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting properties at design-time faster than at run-time? Ronald S. Cook answers 7 October 9th, 2006 06:15 AM
Time Rasputin answers 8 November 14th, 2005 05:28 AM
Delaying viewing of the document pembeci answers 20 July 23rd, 2005 03:56 PM
Real-time graphs answers 12 July 18th, 2005 11:56 AM