Thread: How do you erase display information once it's been entered onto the screen?

  1. #1
    Registered User renurv's Avatar
    Join Date
    May 2005
    Posts
    8

    Cool How do you erase display information once it's been entered onto the screen?

    Hey Fellas,

    I was wondering if I could write a simple code that erases the input display information once a user enters it. For example, I was going to write a simple program that asks for the user's name and then have the trailing display information erased from the program. Here's the code that I wrote:

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    
    {
    
    char name [10];
    
    cout << "May I have your name please?" << endl;
    
    cin    >> name;
    
    cin.ignore();
    
    cout << "Hey, " << name;
    
    cin.get();
    
    return 0;
    
    }
    When the user enters their information their screen would look like this:

    May I have your name please? You
    Hey, You

    ....so my question basically is how do I get rid of "May I have your name please?" so that it looks like this on their screen:

    Hey, You

    ____

    Thanks in advance!

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You can print a '\r' to the screen, which will move the cursor to the beginning of the line. Then you can print spaces until everything is overwritten. Or you can print a '\b', which moves back a single character. Or you can clear the whole screen by printing 25 '\n's. Or you can clear the screen and position the cursor at (0,0) -- see the FAQ.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You'll want to clear the screen. The FAQ link is here: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screen Stream Display Problem
    By mindtrap in forum C# Programming
    Replies: 0
    Last Post: 05-02-2008, 06:54 AM
  2. formating screen information
    By freeman_peterso in forum C Programming
    Replies: 5
    Last Post: 07-10-2003, 06:48 PM
  3. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM
  4. Replies: 6
    Last Post: 07-10-2002, 07:45 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM