Thread: Need Clr Screen Code

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    16

    Need Clr Screen Code

    Does anyone know how I can clear the screen of my program without just putting a bunch of endl; or \n; ??

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    6

    clrscr();

    Use the code clrscr(); to clear the screen

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    When I try to use it, I get an error message saying undeclared indentifier on Visiual C++. Do I have to include any header files?

  4. #4
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    Read the FAQ.

    Brendan
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Does anyone know how I can clear the screen of my program
    Why do you need to clear the screen? In my experience, such functionality is almost never needed. Then there's the portability problem as well. I would wager that you want to clear the screen so that you can print a pretty little menu, am I correct?

    >without just putting a bunch of endl; or \n; ??
    Thats' basically what you end up doing no matter how much abstraction you put around it.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    It's part of an assignment. We have to make a version of the Game "Connect Four" and we're asked to clear the screen so that we can redraw the board.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by mannyginda2g
    It's part of an assignment. We have to make a version of the Game "Connect Four" and we're asked to clear the screen so that we can redraw the board.
    And I bet you still didn't read the FAQ, did you?

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I detect a lot of n00b hate here. Calm down before mannyginda lets off one of those n00b tirades. They are all too common at this time of year.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #9
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Originally posted by bennyandthejets
    I detect a lot of n00b hate here. Calm down before mannyginda lets off one of those n00b tirades. They are all too common at this time of year.
    No need to calm down; it's in the FAQ. Click that. It's a link. To the answer. For your question. Merry Christmas. While you're there, read the rest of the articles.
    Away.

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >It's part of an assignment.
    Take the low road and keep it simple.
    Code:
    void clearscr ( void )
    {
      for ( int i = 0; i < 50; i++ ) // 50 is arbitrary
        cout<<'\n';
      cout<<flush;
    }
    My best code is written with the delete key.

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    header= <stdlib.h> || <cstdlib>

    function= system("cls")

    however i would also advice you to listen to the guys here theyre
    just helping.

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >function= system("cls")
    slow + nonportable = not recommended

    Any program that needs to clear the screen (or thinks it needs to clear the screen) is going to be doing it a lot. Calling speed intensive functions like system frequently is going to slow down the program a great deal. The nonportable part isn't as important since the OP is probably working with Windows exclusively, but it's still a bad habit to get into.

    In general I recommend against using system except when it's really necessary, even if the alternative solution is platform or compiler dependent. Of course, the point is moot if the OP actually looks at the FAQ and uses the function defined there.
    My best code is written with the delete key.

  13. #13
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    thanks for the information prelude.
    i was just telling him that was a possoble way offcourse there are
    alternatives.

  14. #14
    Registered User
    Join Date
    Nov 2003
    Posts
    16
    Thanks guys, nah I did read the FAQ, it helped. It's all love don't worry about it.

  15. #15
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Originally posted by Prelude
    >It's part of an assignment.
    Take the low road and keep it simple.
    Code:
    void clearscr ( void )
    {
      for ( int i = 0; i < 50; i++ ) // 50 is arbitrary
        cout<<'\n';
      cout<<flush;
    }
    is there a better way than this? (my compiler doesn't have clrscr())
    and what does flush do?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Render text
    By Livijn in forum C++ Programming
    Replies: 6
    Last Post: 07-06-2007, 03:32 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. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  4. easy visual c++ program problem,
    By DAIALOS in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2003, 12:38 PM
  5. Shut off DOS screen automatically to Windows
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-08-2001, 07:14 PM