473,395 Members | 2,423 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,395 software developers and data experts.

Delaying the program

23
Is there a way in C++ to delay the program (for example before it displays something or calls a function) by a certain amount of seconds? I know it it possible in JavaScript, but is it in C++? Thank you.
Jan 12 '08 #1
3 2486
weaknessforcats
9,208 Expert Mod 8TB
Depends on the OS. Windows has a Sleep() where you specify the number of microseconds to sleep.
Jan 12 '08 #2
Voltem
3
Is there a way in C++ to delay the program (for example before it displays something or calls a function) by a certain amount of seconds? I know it it possible in JavaScript, but is it in C++? Thank you.
include the <stdlib.h> library and use the code: Delay( );

Example:

Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <iostream.h>
  3. main()
  4. {
  5.    while(!kbhit())
  6.    {
  7.       cout<<"*********";
  8.       delay(100);///////Notice that the value is in miliseconds
  9.    }
  10. }
Jan 12 '08 #3
oler1s
671 Expert 512MB
Voltem’s proposed solution is horribly wrong. Shockingly, each line of code, except for the braces, is questionable. And it’s only 10 lines of code.

#include <stdlib.h> . Old style header. The new form is <cstdlib> . However, it isn’t necessary here.
#include <iostream.h> . Old style header. The new form is <iostream> .
main(). Won’t compile. Only two acceptable forms of main. The one without arguments is int main().
kbhit. conio.h function. However, conio.h is compiler dependent, and has no standardisation. No good.
delay(100). Another conio.h function. That’s right, it doesn’t exist in cstdlib. And by relying on conio.h, you rely on a specific compiler.

Again, the correct way to insert a “pause” is to make the respective thread “sleep”. This is OS dependent. Also, because desktop operating systems are not real time OS, the sleep value is a minimum rather than a precise pause.
Jan 12 '08 #4

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

Similar topics

22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
0
by: Fiona McBride | last post by:
Hi all, I have a really odd problem with some Visual Basic .NET 2003 code; I have a program that creates a number of windows which contain RichTextBox, Timers (disabled) and menus. The code...
11
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
5
by: Sargo | last post by:
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...
1
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
2
by: Gregory A Greenman | last post by:
I have a program that accesses a web service. One of the terms of use of this web service is that I am not supposed to call it more than about once per second. My program currently runs much too...
7
by: Eustace | last post by:
I have a program that contains a do-while loop, inside of which it (re)calculates a array of labels XY, each one consisting of a single digit, and print them forming an x by y rectangle. What I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...

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.