I don't see a delay() in c++!

This is a discussion on I don't see a delay() in c++! within the C++ Programming forums, part of the General Programming Boards category; Hello I would like to ask what's the delay() in vc++ because when I tried using delay, it displays an ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    14

    Unhappy I don't see a delay() in c++!

    Hello I would like to ask what's the delay() in vc++ because when I tried using delay, it displays an error message "delay undeclared identifier".
    Flamers are worst than Newbies

  2. #2
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    I belive it's sleep(). To find out how to use it, look it up on MSDN

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    14
    Yeah I saw sleep in msdn but it's in win32 api! I would like to use it in console app.
    Flamers are worst than Newbies

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Yeah I saw sleep in msdn but it's in win32 api! I would like to use it in console app.
    As long as your console app is being run by Windows (as opposed to actually being MS-DOS or another OS), you can use the sleep() function just like windows.h is another part of the standard library. No need to set up windows.

    If it is another OS you're using, search google for an appropriate API.

  5. #5
    Registered User
    Join Date
    Feb 2004
    Posts
    14
    ok thanks I'll try to play around with it.
    Flamers are worst than Newbies

  6. #6
    Registered User
    Join Date
    Feb 2004
    Posts
    14
    Sleep(DWORD dwMilliseconds); can you give me a clue how to use it? I'm totally clueless my friend.
    Flamers are worst than Newbies

  7. #7
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    DWORD is a double word. It means 4 bytes. It's a term commonly used in assembly programming, and has just been included as another data type in the windows API.

    But it's easier than that. Simply send the number of millisecond (1000 per second) that you want to pause for in the parentheses. If you need to represent this number as a variable instead, I would just look for more information about the DWORD data type at MSDN.

    hint: If you're going to be searching MSDN, both MSDN and many other users recommend using google instead of MSDN's search engine. Type what you want to search for, add "msdn" on the end, and you're all set.

  8. #8
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    Sleep(300)

    btw Sleep() is different than sleep()

  9. #9
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Indeed - C is case sensitive. Make sure you type it correctly.

    And Makoy, please fix that typo in your sig... my biggest problem with newbies is that they rarely write properly. ur l33t yo in the hizzy, playas!

  10. #10
    Registered User
    Join Date
    Feb 2004
    Posts
    14
    [sourcecode]
    #include <stdio.h>
    #include <iostream.h>
    #include <conio.h>
    #include <windows.h>
    void main ()
    {
    char ip[15];

    cout<<"Enter IP Address: ";
    cin>>ip;
    cout<<"\nAttempting To Connect: "<<ip;
    cout<<"\nConnecting";
    Sleep(1000);
    cout<<".";
    Sleep(1000);
    cout<<".";
    Sleep(1000);
    cout<<".";
    Sleep(1000);
    cout<<".";
    Sleep(1000);
    cout<<".";
    Sleep(1000);
    cout<<".";
    Sleep(1000);
    cout<<".";
    }
    [/sourcecode]

    I have this problem that when I execute a file, instead of delaying the "." the delay took effect after I input a file. How can I delay the cout<<"." one by one?
    Last edited by Makoy; 12-25-2004 at 07:58 AM. Reason: wrong php formatting
    Flamers are worst than Newbies

  11. #11
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    1) main should return an int. Also return 0 at the end of your main function.
    2) conio.h is a non-standard header. I don't see why you need it in this program, so don't use it as it will make it difficult for others to help you. It's also bad practice for a number of reasons.
    3) You can edit your post; just take the "source" out of your code and it'll format your code in a nice font and preserve the spacing.

  12. #12
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    @Makoy
    take a look at this:
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main()
    {
    	for(int i=0;i<10;i++)
    	{
    		printf(".");
    		Sleep(300);
    	}
    	return 0;
    }

  13. #13
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    And I just noticed you're using obsolete C++. In the latest standard, you need to do the following:

    - Remove the .h from any standard header files (this does not include windows.h).
    - If you use any of the original C header files, precede them with a 'c'.
    Code:
    #include <cstdlib>
    
    As apposed to
    
    #include <stdlib.h>
    - You need to specify the namespace you are using. There are a number of ways to do this. Personally, I like to just add
    Code:
    using namespace std;
    below my #include's.

    Depending on your compiler, this may or may not be necessary or even allowed. But you should know about it.

  14. #14
    Registered User
    Join Date
    Feb 2004
    Posts
    14
    YES!!! I got it working already. Sorry bout my sig I do not mean to offend anybody. I'll remove it ASAP. Guys Thanks for the help! I really appreciate it.

  15. #15
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You don't have to remove it, if you could just spell "worse" properly.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Regarding delay in the connection
    By byatin in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-19-2008, 03:59 PM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 08:26 PM
  3. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 12:23 PM
  4. 2-3 Second delay with alarm()
    By Longie in forum C Programming
    Replies: 11
    Last Post: 06-20-2004, 09:46 PM
  5. Delay
    By CanadianOutlaw in forum C++ Programming
    Replies: 4
    Last Post: 09-13-2001, 07:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21