Is there anyway we can clear only a selected part of the console window?
clrscr() from conio.h & system("CLS") clears the whole screen.
So how to clear screen selectively?


For example, one of my old code prints this,

Enter the limit for the array size (Max: 20)
10

Enter the elements for the array
1
2
3
4
5
6
7
8
9
10


The greatest interger is  10
The smallest integer is 1

But i want it to be like this, just after the user enters the last element.

Enter the limit for the array size (Max: 20)
10



The greatest interger is  10
The smallest integer is 1

Recommended Answers

All 6 Replies

may be u can use a loop of cout<<endl; statement to get the desired output
or try with graphics.h filling that part of the output with background colour

Depending on which version of C++ you're using...
Borland will allow you to easily set the cursor position and then overwrite what you need.
You can also just KEEP all of the data in an array or list and rewrite just the part you want when the screen is fully cleared.

may be u can use a loop of cout<<endl; statement to get the desired output
or try with graphics.h filling that part of the output with background colour

But how do you think i can go to a previous line? Any Idea? Thanks for the post...

Depending on which version of C++ you're using...
Borland will allow you to easily set the cursor position and then overwrite what you need.
You can also just KEEP all of the data in an array or list and rewrite just the part you want when the screen is fully cleared.

Well i am using Microsoft Visual C++ 2010 Express edition, but to my surprise, it have all the Turbo C++ exclusive header files, like conio.h, math.h (I presume, we use cmath in modern compilers) etc etc etc.....Not sure, this is because i installed VC++, even though i had TC++ installed....

Well back to the topic, How can i set the cursor position in TC++? And how to get the coordinates of cursor position. Please show me an example, that would be very kind of you.

Here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682022(v=VS.85).aspx

Disregard the first example and scroll down to see proper handling of a Windows console.

Would that let me delete part of the console, which have already been printed? Asked because i found it little hard to understand. And can you help me with how to find the mouse coordinates to be assigned in that example? Thanks for the help...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.