473,414 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to simulate time in C++

How do I simulate time in C++?
For example I want:
Expand|Select|Wrap|Line Numbers
  1. printf("\a\a\a");
  2. half a second passes;
  3. printf("\a\a");
Oct 31 '08 #1
4 3924
sicarie
4,677 Expert Mod 4TB
I'd recommend the Sleep() function.
Oct 31 '08 #2
donbock
2,426 Expert 2GB
It depends on what libraries you've got. The sleep function is not part of the language specification, so it isn't present on all platforms.

I'm not familiar with the C++ Standard Library, but in C the most portable method is to spin on the time() function until difftime() tells you that the desired amount of time has passed. Refer to <time.h>.

A spin-loop like this is just about the worst thing you can do in a multi-tasking environment. You may have to use a nonportable technique. If so, then we would need to know more about your run-time environment -- especially what operating system you're using.
Oct 31 '08 #3
Arepi
62
Hi!

You can use also the function delay(millisec); (#include <dos.h>)
when it possible in your system
Oct 31 '08 #4
Studlyami
464 Expert 256MB
Well this will depend on how precise you need the timer. On a windows platform you can use GetTickCount() if you only need the time in milliseconds and you don't need a long lasting timer. You can also create a timer, but its best if you just read up on them.. If you need a more percise timer you can goolge for high resolution timers in C++ and come up with a lot of information about them.
Nov 1 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Michael J Whitmore | last post by:
Greetings, I have a very simple question. How do you simulate a user input to turn off a screen saver in Windows (either a mouse movement, mouse click, or keyboard input)? I promise I searched...
1
by: charliewest | last post by:
I am trying use server controls or web controls to simulate the following behavior. I've an image wrapped w/in a link to create a rollover effect as if both elements we're one graphic: <a...
2
by: Zhaozhi Gao | last post by:
I'm doing a simple project for school. This is the first time I've ever used Access. Is there a way i can simulate a Circular Queue data structure for the datas in a table. I tried assign index...
61
by: /* frank */ | last post by:
I have to do a homework: make a CPU simulator using C language. I have a set of asm instructions so I have to write a program that should: - load .asm file - view .asm file - do a step by step...
4
by: johnny | last post by:
On a form I would like to simulate a button click when the Enter is pressed. My form is setup and it works if the delegate for the key pressed on the form calls the delegate for the button pressed....
2
by: Eli | last post by:
HI! I made some quiz using one HTML form (few question with few radio-button each like potential answers) that have one Submit button. I would like to simulate click on this button (e.g. named...
8
by: Doug Marquardt | last post by:
Hi All: I want to simulate VB6 Autoredraw in VB.Net I figure I would probably have to create a memory dc, paint to that, and then create a bitmap based on the dc and copy that image into a...
2
by: cpptutor2000 | last post by:
Could some C guru suggest some possible solution to my problem? I am trying to simulate a clock and I have tried using 'gettimeofday' and some related C library functions, but I am not getting what...
1
by: =?Utf-8?B?UmljYXJkbyBRdWludGFuaWxsYQ==?= | last post by:
how to simulate a different time zone? ¿is it possible by code to simulate that i am in a different time zone just for to execute a few lines of code? in my case i am in the time zone...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.