Thread: How do you clear the screen?

  1. #1
    Unregistered
    Guest

    Unhappy How do you clear the screen?

    I went to FAQs and there ways don't work. The only one that works is throwing the monitor out the window. If anyone has a suggestion please let me know.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Compiler and OS?

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    6
    #include <mem.h>

    unsigned char * vga = NULL; // pointer to vga mem
    vga = (unsigned char *) 0xA000; // set it

    void clearscreen (int colour) {

    memset(vga, col, (width * height) converted to hex);

    }

    remember this will leave your screen cleared, so if you cleared it to colour 4 you would get a blank red screen, and you would need to cout << some text over it, remembering that text is WHITE!

    this function might not work unless you have set a resolution IN your program yourself ie.

    asm xor ah, ah
    asm mov al, 0x13
    asm int 10h

    places you in 320 * 200 mode and the clearscreen func would be

    memset(vga, col, 0xFA00);

    0xFA00 = 320 * 200 (converted to hex (use windows calculator))

    Hope this helps

    UncleG

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    11

    Vis C++

    Well in Vis C++ (version 6, at least) you can do:

    Code:
    system("cls")
    Not sure what library files you need, maybe windows.h
    Before you criticise a man, walk a mile in his shoes. Then, when you criticise him, you're a mile away. And you have his shoes.

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    To clear screen in DOS text mode:

    clrscr() <conio.h>

    To clear screen in DOS BGI:

    cleardevice() <graphics.h>

    To clear screen permanently:

    Throw the monitor out the window.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    13

    Cool The answer to clearing the screen, in a simple function...

    //
    void clrscr();//Prototype for the clear screen function
    int main()
    {
    cout << "whatever";//Text to screen
    clrscr();//Calls to clear the screen
    return 0;
    }

    void clrscr() //Clears the screen
    {
    COORD coordScreen = { 0, 0 };
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD dwConSize;
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    GetConsoleScreenBufferInfo(hConsole, &csbi);
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
    GetConsoleScreenBufferInfo(hConsole, &csbi);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
    SetConsoleCursorPosition(hConsole, coordScreen);
    }
    ~Silencer~
    What is this "C.O.D.E." you speak of?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CLear Screen Routine
    By AQWst in forum C++ Programming
    Replies: 4
    Last Post: 12-13-2004, 08:24 PM
  2. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  3. Getting a clear screen...
    By Finchie_88 in forum C++ Programming
    Replies: 13
    Last Post: 09-03-2004, 05:38 PM
  4. Clear Screen Again!!!
    By trang in forum C Programming
    Replies: 3
    Last Post: 12-13-2003, 08:36 AM
  5. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 05:14 AM