Is there a way to stop my console application from scrolling when new text is added? In my application, I am adding new text and I don't want the console to scroll to the bottom each time that happens, I just want it to stay at the top the whole time.
This is for Windows, using the Win API.
CodePudding user response:
You can try writing system("cls");
to clear the screen and write from the top again.
CodePudding user response:
If you're using printf
- Do not end your lines with \n
- Start each line with \r. This will cause the program to continuously overwrite the line where you first started printing
- Add a fflush to flush the buffer
If you're using std::cout,
- Do not end your lines with std::endl
- Start each line wiht \r
- Add std::flush at the end of line
The only problem is that if the new line is shorter than the previous line, the text may not be overwritten.