Thread: clearing screen

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    clearing screen

    this is the only other one besides clrscr i liked but it didnt work so i used

    Code:
    #include<iostream>
    #include<conio.h>
    #include<stdio.h>
    using namespace std;
    int main(void)
    {
      int i;   
    cout<<"hello world\n";
    cin.get();
      for (i = 0; i < 25; i++)
        putchar ('\n');
        cin.get();
        
      return(0);
    }
    but then it puts you at the bottom of the page i want the top how do i do that

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    There is no standard way so you can use clrscr() if your conio.h has it or if you are under windows you can use system("cls"). I can't remember the *nix command to clear the screen.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    There's no standard way of not reading the FAQ either, but newbies always find lots of interesting ways of not reading it.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by Salem
    There's no standard way of not reading the FAQ either, but newbies always find lots of interesting ways of not reading it.
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    Priceless
    (Sorry I had to say it)
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I usually do it like this:
    Code:
    #include <cstldib>
    
    //change "clear" to "cls" for win32
    inline void clearScreen() { system("clear"); }
    of course, you then have to deal with having a potential security hole in your program, but it's a quick and dirty way to get it done, plus it saves you the pain of changing your code in multiple places.

    If you don't know how to use it, just call clearScreen() everywhere you need to clear the screen, and it'll call whatever program you tell it to to do your dirty work for you.

    edit: I don't actually usually clear the screen - avoid it if at all possible.

    edit2: even using this method (I'm using gentoo, hence the linux command), the screen's buffer isn't cleared... you can still scroll up in a console and see everything that was there. I think in windows it may actually clear the buffer (or at least hide it's contents)
    Last edited by major_small; 10-08-2005 at 12:41 AM.
    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

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >#include <cstldib>
    I'm told there's help for lysdexic people. But seriously, is cstldib the header where undefined_behavior ( bosses_email_address ) and read_my_mind() is?
    My best code is written with the delete key.

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    meh... I haven't touched a line of code in over a month... and my mind is in other places

    Code:
    #include <cstdlib>
    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. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  3. clearing the screen
    By ssharish in forum C Programming
    Replies: 2
    Last Post: 02-01-2005, 09:00 PM
  4. 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
  5. Clearing the screen
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 05-23-2002, 01:40 PM