Clear screen

For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)

And while I'm at it, since I'm new to message boards, I was just wondering: Whenever somebody posts an answer to one of my questions and solves my problem, my natural impulse is to e-mail that person to say thanks. However, I thought I had better check on the obvious etiquette issue: Is e-mailing one's thanks considered unnecessary, or perhaps even a minor annoyance (i.e., yet another e-mail to read)? Or on the contrary, is this appreciated? Alternatively, perhaps I should just say "thanks in advance" when posting my question? What is the established practice in this regard?

Comments

  • : For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)

    No, there is no standard function to clear the screen. The standard doesn't think of screens and keyboards, everything is just a stream. If you are going to do complex console manipulation (and that may include even simple things like clearing the screen) then you should use a cross-platform library such as ncurses or SLang. For clearing the screen though, you can just spew a bunch of newlines out and that should get the necessary effect.

    :
    : And while I'm at it, since I'm new to message boards, I was just wondering: Whenever somebody posts an answer to one of my questions and solves my problem, my natural impulse is to e-mail that person to say thanks. However, I thought I had better check on the obvious etiquette issue: Is e-mailing one's thanks considered unnecessary, or perhaps even a minor annoyance (i.e., yet another e-mail to read)? Or on the contrary, is this appreciated? Alternatively, perhaps I should just say "thanks in advance" when posting my question? What is the established practice in this regard?
    :

    These are just my personal views.

    Don't email me. If you really want to email me, then use the Programmer's Heaven mail system (i.e. "Write Message"). Of course, don't bother just to say thanks. No one will complain if you say, "Thanks, that solved my problem" as a reply (obviously don't post a new thread for that). I personally, don't like "Thanks in advance". Actually, that's not accurate, I don't care (actually I don't care about thanks at all). However, I find it ridiculous for anyone to say thanks in advance, when they quite possibly might get no help at all. Also, though I don't care about thanks, I do kind of like knowing that the problem is over and done with. So posting a reply once the problem is solved is nice. As far as I'm concerned, just "It worked", or better "It worked, but I had to do X and Y as well to get it to work", or "I decided to try something else", or anything that might be helpful is enough.

    While typically this is given to people who have violated every reasonable posting practice, you may also find some things that will give you an idea of what you should do, what things to avoid, and how to maximize the quality and speed of the replies you get,
    http://www.tuxedo.org/~esr/faqs/smart-questions.html


    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • You mean like:

    system("CLS");

    ..or:

    #include
    clrscr();
  • : You mean like:
    :
    : system("CLS");
    :
    : ..or:
    :
    : #include
    : clrscr();
    :

    Neither of which are standard.

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • : For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)

    I used to submit to BeOS mailling lists in the past, and someone from BeCodeTalk gave an interesting way to clear the screen:

    printf("33[H33[J");

    Not very sure why it works though, or even what it means.....
    Of course, this method would probably be far from "standard".
  • : : For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)
    :
    : I used to submit to BeOS mailling lists in the past, and someone from BeCodeTalk gave an interesting way to clear the screen:
    :
    : printf("33[H33[J");
    :
    : Not very sure why it works though, or even what it means.....
    : Of course, this method would probably be far from "standard".
    :
    What that does is send terminal codes to the screen 33 is ESC. It won't work in general, it will only work for terminals where that escape sequence means clear the screen. However, for, for example, the Windows command prompt, that wouldn't work.

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • : You mean like:
    :
    : system("CLS");
    :
    : ..or:
    :
    : #include
    : clrscr();
    :
    [hr]Thanks for the tip. clrscr(); doesn't work for me, despite my including ("warning: 'clrscr' undefined...). However, system("CLS"); works fine.[hr]
  • : : You mean like:
    : :
    : : system("CLS");
    : :
    : : ..or:
    : :
    : : #include
    : : clrscr();
    : :
    :
    : Neither of which are standard.
    :
    : "We can't do nothing and think someone else will make it right."
    : -Kyoto Now, Bad Religion
    :
    :
    [hr]Thanks for the tip. clrscr(); doesn't work for me, despite my including ("warning: 'clrscr' undefined...). However, system("CLS"); works fine.[hr]
  • : : For command-line programs in C and C++, is there a standard library function to clear the screen? I've looked pretty carefully, but have found none. (I realize that it is easy to write one oneself, but I figure that this would just add a bit more unnecessary clutter to my code.)
    :
    : I used to submit to BeOS mailling lists in the past, and someone from BeCodeTalk gave an interesting way to clear the screen:
    :
    : printf("33[H33[J");
    :
    : Not very sure why it works though, or even what it means.....
    : Of course, this method would probably be far from "standard".
    :
    [hr]Thanks for the suggestion. Actually, I'm afraid I wasn't able to get it to work. However, somebody else suggested the following, and it works fine:

    #include or

    system("CLS");[hr]
  • : : You mean like:
    : :
    : : system("CLS");
    : :
    : : ..or:
    : :
    : : #include
    : : clrscr();
    : :
    : [hr]Thanks for the tip. clrscr(); doesn't work for me, despite my including ("warning: 'clrscr' undefined...). However, system("CLS"); works fine.
    ...
    Until you recompile for Linux (let's say) and get

    bash: cls: command not found

    as output anytime you try to clear the screen.

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • if your output window's 25 rows, use this:

    [code]{
    for (register int i = 0; i < 25; i++)
    puts("");
    }[/code]
  • : if your output window's 25 rows, use this:
    :
    : [code]{
    : for (register int i = 0; i < 25; i++)
    : puts("");
    : }[/code]
    :
    [hr]Thanks! Somebody else suggested the following:

    [code]system("CLS");[/code]
    ...and it works well, too.
    [hr]
  • after my statements're executed, the insertion point'll not located at the beginning of the screen.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories