Question About Delaying A Cout Display

This is a discussion on Question About Delaying A Cout Display within the C++ Programming forums, part of the General Programming Boards category; Alright, so I'm working on this nifty RPG I wanted to make.. everything is going good ( it's a pretty ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    67

    Question About Delaying A Cout Display

    Alright, so I'm working on this nifty RPG I wanted to make.. everything is going good ( it's a pretty simple, adventure game.. just text, no object-orientated programming yet.) And I always wanted to know how to delay certain parts of a string display such as in the cout funtion. I will show you an example of what I am talking about, and I will split up the paragraph into numbered sentences and tell you which sentence is the one I want to delay.

    For example:

    1. "You entered the cave."

    2. "Shining your flashlight straight ahead, you see hundreds of red eyes glaring right at you."

    3. " . . . ."

    4. "You realize your not alone."

    Now for each sentence, the user will be pressing enter to make the next one appear. The sentence I want to delay is #3:

    ". . . ."

    I want to delay each dot appearing about 3/4 of 1 sec. So, like this:

    1 sec = ". "

    2 sec = ". ."

    3 sec = ". . ."

    4 sec = ". . . ."

    ect..

    And I want it to stay all in one line.

    I've tried googling this, but what I'm typing in at the search bar leads to unrelated results... any one with experience in this certain kind of programming, can you please tell me what functions this is, and where to get started?

    Please and thank you !

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    There is a function called sleep/Sleep (depends on your OS/compiler) that tells the program to wait for a certain time period. You could do that in a loop displaying one dot each second.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    67
    Quote Originally Posted by hk_mp5kpdw View Post
    There is a function called sleep/Sleep (depends on your OS/compiler) that tells the program to wait for a certain time period. You could do that in a loop displaying one dot each second.
    Thank you so much for your help! I was able to google this and gather more info on this function. I appreciate your quick reply! =)

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    67
    I'm kind of caught in a snag now... My OS is a windows and I'm using Code::Blocks, yet it seems that the sleep function does not work... any advice?

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Code::Blocks is an IDE (Integrated Development Environment)... it is not a compiler. Under the hood, Code::Blocks uses a compiler - from another software vendor - to produce the actual code. An IDE is a pretty environment you can type your code into and which helps to automate many tasks involved in software development. To my knowledge, Code::Blocks support the following compilers: MinGW / GCC, Digital Mars, Microsoft Visual C++, Borland C++, Watcom, LCC and the Intel C++ compiler. Not all of those are targeted towards Microsoft Windows (which you are using).

    Now, enough of that and back to the issue at hand. How are you using the function? Showing some code would be nice right about here. The Sleep function (notice case is important here) is prototyped in the windows.h header which you should be including and takes its argument in milliseconds. Thus, Sleep(1) means "sleep for one millisecond", it does not mean "sleep for 1 second". If you did the first one, you might think that it's not working but it actually is... just not as you think it should be working. Since one second is equal to 1000 milliseconds, to sleep for 1 second you must call Sleep(1000).
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    67
    Quote Originally Posted by hk_mp5kpdw View Post
    Code::Blocks is an IDE (Integrated Development Environment)... it is not a compiler. Under the hood, Code::Blocks uses a compiler - from another software vendor - to produce the actual code. An IDE is a pretty environment you can type your code into and which helps to automate many tasks involved in software development. To my knowledge, Code::Blocks support the following compilers: MinGW / GCC, Digital Mars, Microsoft Visual C++, Borland C++, Watcom, LCC and the Intel C++ compiler. Not all of those are targeted towards Microsoft Windows (which you are using).

    Now, enough of that and back to the issue at hand. How are you using the function? Showing some code would be nice right about here. The Sleep function (notice case is important here) is prototyped in the windows.h header which you should be including and takes its argument in milliseconds. Thus, Sleep(1) means "sleep for one millisecond", it does not mean "sleep for 1 second". If you did the first one, you might think that it's not working but it actually is... just not as you think it should be working. Since one second is equal to 1000 milliseconds, to sleep for 1 second you must call Sleep(1000).


    Thank you for correcting me on what a compiler is... Kind of feel stupid right about now haha. Anyways, I was able to get the program to work! I had just forgot the header file <windows.h> ( silly me....)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Delaying a program
    By 7h3_0r4c1_3 in forum C Programming
    Replies: 14
    Last Post: 10-03-2011, 01:09 PM
  2. cout question
    By arian in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2010, 06:59 AM
  3. Replies: 2
    Last Post: 01-22-2008, 04:22 PM
  4. cout fraction display
    By CheyenneWay in forum C++ Programming
    Replies: 7
    Last Post: 05-07-2004, 10:17 AM
  5. delaying for milli, microseconds
    By wazilian in forum C Programming
    Replies: 3
    Last Post: 10-23-2001, 02:44 PM

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