-4

Okay , I'm writing my first project for my college , I need to make a trick in my code which i believe it's possible to do , First of all here's my code :

cout << "1 - Enter the program\n" 
     << "2 - About the program\n"
     << "3 - EXIT" << endl; //calls exit function .
cin >> choice;

After this very first line of code execution , the compiler calls a function which also has a bunch of couts and cins ,

click here to understand more

What exactly i need to make is when i choose 1 or 2 all the previous words should be cleared except the program title .

something like this

  • Take a look at the information contained in this question: https://stackoverflow.com/questions/6486289/how-can-i-clear-console – jpw Aug 02 '16 at 14:54
  • yeah this is a better title and i got it , thanks mate – Hussam Elshehawy Aug 02 '16 at 14:56
  • 1
    It's great to see that these college projects make such didactic sense, reflective of the most skilled, committed professors. I especially like the ones that insist that the student, say, instantiate a hierarchy of classes and follow various design patterns in order to, say, add two integers. – Bruce David Wilner Aug 02 '16 at 15:05
  • If your text can fit on a single line, drop the endl and leave the cursor at the end. After the user makes a selection, blast a number of backspace characters `\b` to erase all of the characters on that line. – David Thomas Aug 02 '16 at 15:07
  • You can also try VT100 control sequences. Windows 10 just brought back support. I used to have a ton of these memorized (it's been a while) so the sequence to clear the screen or line `ESCAPE`s me. – David Thomas Aug 02 '16 at 15:10

2 Answers2

1

All you can do with vanilla C++, I believe, is to print enough blank lines and then reprint the title. If you wish to really clear the screen, and all sorts of other things with the console, you should use ncurses or PDCurses library.

Franko Leon Tokalić
  • 1,457
  • 3
  • 22
  • 28
0

I wouldn't mess with libcurses. I would mechanically clear the screen by outputting however many newlines (probably 24) and then just hand-coding everything else. If you want to use escape codes, assume the proper terminal type (most college computer labs don't have umpteen flavors of terminals in the general access area) and hand-code the sequences rather than trying to figure out curses.

Cameron Skinner
  • 51,692
  • 2
  • 65
  • 86