Connecting Tech Pros Worldwide Help | Site Map

time delaying?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 11:31 PM
Sargo
Guest
 
Posts: n/a
Default time delaying?

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 22nd, 2005, 11:31 PM
Sargo
Guest
 
Posts: n/a
Default 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 22nd, 2005, 11:31 PM
ajk
Guest
 
Posts: n/a
Default 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 22nd, 2005, 11:31 PM
Victor Bazarov
Guest
 
Posts: n/a
Default 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 22nd, 2005, 11:32 PM
Jerry Coffin
Guest
 
Posts: n/a
Default 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 22nd, 2005, 11:32 PM
Victor Bazarov
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.