How can I overwrite the same portion of the console in a Windows native C++ console app, without using a 3rd Party library?

前端 未结 5 908
忘了有多久
忘了有多久 2020-12-09 11:31

I have a console app that needs to display the state of items, but rather than having text scroll by like mad I\'d rather see the current status keep showing up on the same

5条回答
  •  温柔的废话
    2020-12-09 11:48

    If you print using \r and don't use a function that will generate a newline or add \n to the end, the cursor will go back to the beginning of the line and just print over the next thing you put up. Generating the complete string before printing might reduce flicker as well.

    UPDATE: The question has been changed to 2 lines of output instead of 1 which makes my answer no longer complete. A more complicated approach is likely necessary. JP has the right idea with the Console API. I believe the following site details many of the things you will need to accomplish your goal. The site also mentions that the key to reducing flicker is to render everything offscreen before displaying it. This is true whenever you are displaying anything on the screen whether it is text or graphics (2D or 3D).

    http://www.benryves.com/tutorials/?t=winconsole

提交回复
热议问题