Results 1 to 5 of 5

Thread: Clear console

  1. #1

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Unhappy

    How can I clear the text of a console window?

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    If you're using Borland you can use the clrscr() function, otherwise you could print however many newlines as there are lines on the screen. I don't remember how many that is.
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Angry Using C++

    I'm using C++, so clrscr() doesn't exist.
    What you said about inserting a lot of empty strings, does clear the screen, but then when I insert normal text again, it comes at the bottom of the console, and not at the top.

    Any other suggestions?

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  4. #4
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Try this, put this in your iostream.h file:

    #if defined(BORLAND_C)
    #include <conio.h>
    #define cls() clrscr()
    #endif

    #if !defined(BORLAND_C)
    #include <stdlib.h>
    #define cls() system("cls");
    #endif

    Then whenever you want to clear it, just do cls().

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's never a good idea to alter the system headers. Put it into a header file of your own if you need to use it. Also, this is slightly more elegant:
    Code:
    #include <conio.h>
    #include <stdlib.h>
    
    #if defined(BORLAND_C)
        #define cls() clrscr()
    #elseif
        #define cls() system("cls");
    #endif
    If the files are included unnecessarily it won't make any difference because anything that's not used will be removed by any optimising compiler anyway.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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