Thread: How do I slow down output?

  1. #1
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Question How do I slow down output?

    How do I slow down output made through cout?
    When output strings are too long to fit inside the Terminal or Command Prompt window, I want to make the text scroll slow enough to read.

    Thanks in advance.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    You can do it Zelda style just by outputting a character at a time, and using a timer to wait in between characters. This method requires that you put everything into strings first.

  3. #3
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by whiteflags View Post
    You can do it Zelda style just by outputting a character at a time, and using a timer to wait in between characters. This method requires that you put everything into strings first.
    Good idea.
    Where do I get the timer?
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The easiest way is to just Sleep between each output.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I think it is also common to prompt the user to press Return to get the next "page" of output.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by anon View Post
    I think it is also common to prompt the user to press Return to get the next "page" of output.
    Hmm...yeah, that might be a better solution.
    However, do you have any idea how many lines can be displayed in a normal-sized Linux Terminal or Windows Command Prompt, and are the number of lines the same (I guess probably not, eh?)?
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  7. #7
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by Elysia View Post
    The easiest way is to just Sleep between each output.
    Isn't Sleep (or "sleep()") a Windows-specific function? I was wanting my program that will use this to be cross-platform, and therefore I would like the method of slowing down output (if I decide to even use this approach) to be cross-platform as well.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    There is a standard way to do what I was saying, posted here. But it sounds like the other thing is better, anyway. For a good console size, I don't think you can go wrong with 80 characters x 25 lines so just work around that.

  9. #9
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827
    Quote Originally Posted by whiteflags View Post
    There is a standard way to do what I was saying, posted here. But it sounds like the other thing is better, anyway. For a good console size, I don't think you can go wrong with 80 characters x 25 lines so just work around that.
    Thanks.
    I'm an alien from another world. Planet Earth is only my vacation home, and I'm not liking it.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Programmer_P View Post
    Hmm...yeah, that might be a better solution.
    However, do you have any idea how many lines can be displayed in a normal-sized Linux Terminal or Windows Command Prompt, and are the number of lines the same (I guess probably not, eh?)?
    Not standard. It is configurable. The only way to know is to use Windows API, which you want to avoid in the first place.

    Quote Originally Posted by Programmer_P View Post
    Isn't Sleep (or "sleep()") a Windows-specific function? I was wanting my program that will use this to be cross-platform, and therefore I would like the method of slowing down output (if I decide to even use this approach) to be cross-platform as well.
    It is. But there is no portable way of doing without wasting lots of cpu resources. You could just limit yourself to Windows and Linux.

    Quote Originally Posted by whiteflags View Post
    There is a standard way to do what I was saying, posted here. But it sounds like the other thing is better, anyway. For a good console size, I don't think you can go wrong with 80 characters x 25 lines so just work around that.
    Why? WHY??? This is the very exact thing we suggest people avoid!
    Delay loops are frowned upon, so why would you suggest it? I don't understand.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    He asked for a standard way. I couldn't do anything about how much standard code sucks in that situation. Make me a martyr for it.

  12. #12
    C++ Junkie Mozza314's Avatar
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    174
    What I'd really like to know is - why the hell don't we have a good standard way of doing this?

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Probably not useful enough. The committee have limited resources and has to prioritize. That's my guess, anyway.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Slow character output...
    By |<4D4\/eR in forum C++ Programming
    Replies: 4
    Last Post: 04-16-2002, 09:10 AM