Results 1 to 6 of 6

Thread: Clear Screen

  1. #1

    Thread Starter
    Addicted Member Ramandeep's Avatar
    Join Date
    Feb 2000
    Posts
    158

    Clear Screen

    Is there a simple way to clear the CONSOLE screen under C++. In Pascal you use clrscr to clear the screen. How can I clear the screen under C++.

    I will also be running the same program under the UNIX OS and don't want anything that is specific to the WINDOWS OS.

    THANKS IN ADVANCE

  2. #2
    If you have a Borland compiler (and abdul thinks this works under Borland too):
    Code:
    #include <conio.h>
    
    clrscr();

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    That's a Borland thing. Borland consoles aren't the same as VC++ consoles, they have some extra stuff built into them.

    As far as I know (I've read a lot of threads discussing this very topic) there is no platform-independant way to do it. If there is, I want to know

    You can use the Shell() function to send a command to the command prompt, but the command to clear the console will be different on different systems. On Linux it's clear, on DOS it's cls.

    In the case of Linux (well, all the bash prompts I've used anyway), the clear is just a lot of newlines - just enough to make the existing text scroll off the top of the screen. You can do a similar thing with DOS. The problem with this is:

    - how many lines do you need to add? It may not be constant
    - it's slow

    If anyone knows how to do this in a OS-independant way, I'd be very interested.
    Harry.

    "From one thing, know ten thousand things."

  4. #4
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151
    If trying to be fast there is no OS independent way to clear the screen. If you'r useing the console you'r probly not trying to be fast, so this should work on any OS.

    Code:
    void ClearScreen()
    {
    	for(int c = 0; c < 1000; c++)
    		cout << endl;
    
    }
    if you want to clear the screen fast you have to get into the API of what ever operating system you're using. Like the FillConsoleOutputCharacter function in the windows API.

  5. #5
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151
    Yes but you only wanted to clear the screen right.
    I only know move the cursor using windows API

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Why not change some code (for clearing the screen) if you want it to run on Linux.
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width