You are here:

C++/pausing cout

Advertisement


Question
Hi David,

how do I 'pause' execution of a routine (cout), or delay events in console C++? I assume the ctime library can be used somehow. The objective is to slow down console scrolling/displays to make them more visible, or to wait for user input in a game program. I am using MSVisual C++ 5.0 on Windows 2000 pro (for console) and Metrowerks code warrior 6.0, Win 98, console.
Thanks!

Tord

Answer
Tord , Thank you for your question.

I don't believe that the I/O system has the capability of sending or receiving I/O events slowly, however you may be able to achieve the same result in other ways.

One possibility is to write a "wrapper" function around printf or some of the ostream functions that would send a character then wait for a few milliseconds, using a high-resolution timer or the Sleep function or a message loop.

Another possibility is to create a Windows hook for character output that would maintain a queue of output events and send them slowly (the thread message queue can't be used to store many messages on some versions of Windows), or would run in a separate thread.

Ideally, you probably want to do panning, not slowing of character output. Panning requires direct access to the console as a pixel-level scrolling window, which I believe is not supported. Since you seem to be working under Windows, I would recommend that you give up the Console mode and use Windows directly. Console mode is only really supported for compatible execution of old MSDOS programs and batch files.

David Spector

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.

Experience

I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Publications
Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

Education/Credentials
ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.