time delaying? 
July 23rd, 2005, 12:31 AM
| | | |
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 | 
July 23rd, 2005, 12:31 AM
| | | | 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. | 
July 23rd, 2005, 12:31 AM
| | | | 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. | 
July 23rd, 2005, 12:31 AM
| | | | 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 | 
July 23rd, 2005, 12:32 AM
| | | | 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. | 
July 23rd, 2005, 12:32 AM
| | | | 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 |  | | | | /bytes/about
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 225,689 network members.
|