0

I have a problem, I to need clean part of the screen instead of all.

For example:

#include <iostream>
using namespace std;
int main ()
{
    string name, city;
    int age;
    cout<<"Enter your name"<<endl;
    cin>>name;
    cout<<"Enter your age"<<endl;
    cin>>age;
    cout<<"Enter your city"<<endl;
    cin>>city;
    cin.get();
    cin.get();
    return 0;
}

Suppose the user enter a number in the city variable, I can create a condition If to clean the screen, but I don't want to clean everything, only the last part.

Les
  • 3,150
  • 4
  • 29
  • 41
Malthael
  • 121
  • 2
    You need to use a library like `ncurses` to do screen manipulation. Standard C++ doesn't provide any provision for this. – Barmar Sep 15 '16 at 02:29
  • 2
    AFAIK, there is no standard way to do this. Terminal hacking is always a delicate business. A good answer would involve mentioning the particular platform you have in mind. For example, this would be possible using libncurses on Posix. You will usually get better answers on SO if you tag the question with your intended target platform. – jforberg Sep 15 '16 at 02:29

2 Answers2

0

You can't change unix-shell ui from C++ (actually you can but trust me you don't want to deal with it)

if you want to write some UI using C/C++ check GTK.

and for your particular case I guess cleaning all the screen and repainting some texts will be enough.

user1040363
  • 139
  • 1
  • 8
0

You can clear the last line only, in most teminals, by printing the character '\r'. This is the ASCII carriage return, which historically made the head of a teletype machine move back to the left.

Another option is to clear the screen with '\L' and reprint the parts you want to stay on the screen. Unless you’re on a very slow connection, there won’t be noticeable flicker.

Davislor
  • 14,674
  • 2
  • 34
  • 49