Wait, pause, sleep, w/e

3

3than7

Im in the video club at my school, and for a presentation were making,
we need some computer scenes.

Each of the characters has an ID wich i have used as an IF function so
typing the right id # goes to the specified character. For the next
part, i have a bunch of text that makes little sene but sounds
"computery" to a non comupter literate person. Basically connecting,
database, and mainframe thrown around, if u can understand that.
For the connecting part, i would like to make the word connecting
appear ( using cout<<"connecting\n"; ) For the next part, . . . how
do i make the periods come onto the screen once every say, 2 seconds so
it looks like its actually loading something.
Rember, this isnt a purposeful program, its intended to look computery,
and thats about all

thanks for any help,,, ~3than
 
M

Mike Wahler

3than7 said:
Im in the video club at my school, and for a presentation were making,
we need some computer scenes.

Each of the characters has an ID wich i have used as an IF function so
typing the right id # goes to the specified character. For the next
part, i have a bunch of text that makes little sene but sounds
"computery" to a non comupter literate person. Basically connecting,
database, and mainframe thrown around, if u can understand that.
For the connecting part, i would like to make the word connecting
appear ( using cout<<"connecting\n"; ) For the next part, . . . how
do i make the periods come onto the screen once every say, 2 seconds so
it looks like its actually loading something.
Rember, this isnt a purposeful program, its intended to look computery,
and thats about all

thanks for any help,,, ~3than


#include <ios>
#include <iostream>
#include <ctime>
#include <string>

void status (const std::string text,
unsigned int duration,
unsigned int interval)
{
std::cout << text;
std::time_t last;
std::time_t begin(std::time(0));

while(std::difftime(last = std::time(0), begin) < duration)
{
while(std::difftime(std::time(0), last) < interval)
; /* empty statement */

std::cout << '.' << std::flush;
}
}

int main()
{
status("connecting", 10, 2);
std::cout << " Done.\n";
return 0;
}


-Mike
 
3

3than7

Mike said:
#include <ios>
#include <iostream>
#include <ctime>
#include <string>

void status (const std::string text,
unsigned int duration,
unsigned int interval)
{
std::cout << text;
std::time_t last;
std::time_t begin(std::time(0));

while(std::difftime(last = std::time(0), begin) < duration)
{
while(std::difftime(std::time(0), last) < interval)
; /* empty statement */

std::cout << '.' << std::flush;
}
}

int main()
{
status("connecting", 10, 2);
std::cout << " Done.\n";
return 0;
}


-Mike


Thank you very much, but is this the simpilist way to do this, because
i'd like to be able to use this feature elsewhere, and im not sure
exactly what you did there. Thanks ALOT thou, very helpfull.
 
A

Alan Johnson

3than7 said:
Thank you very much, but is this the simpilist way to do this, because
i'd like to be able to use this feature elsewhere, and im not sure
exactly what you did there. Thanks ALOT thou, very helpfull.

There are other options depending on your platform. POSIX systems have a
"sleep" function, for example. The advantage of Mike Wahler's approach
is that it is all standard C++, so it should work anywhere that has a
C++ compiler.
 
3

3than7

yes, i played around with it and figured out how to make it work for my
purposes
thanks a bunch mike!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top