Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pause inside a while.

Status
Not open for further replies.

WilliamGS

Programmer
Jan 21, 2004
54
PE
Hi all, is possible make a pause (for 1 second) inside a while?

Thank you.
William G.S.
 
Hi,
here is a somewhat portable sleep function(I only have tested under win XP) :
Code:
#ifndef _WIN32
# include <unistd.h>
#else
# include <windows.h>
#endif

#include <iostream>
#include <assert.h>

//Suspend execution of the calling process for ms milliseconds.
void wait_for (int ms)
{
  assert (ms >= 0);//positive_argument
#ifndef _WIN32
  usleep (ms);
#else
  Sleep (ms);
#endif
}

//little test
int main ()
{
  std::cout << "waiting 2 seconds ..." << std::endl;

  wait_for (2000);

  std::cout << "finished" << std::endl;

  return 0;
}

--
Globos
 
Sleep(1000)

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top