Clearing Screen

This is a discussion on Clearing Screen within the C++ Programming forums, part of the General Programming Boards category; Hey, i'm writing a pretty basic program using Dev C++ and i'm using a seriesof IF statements to create a ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    5

    Clearing Screen

    Hey, i'm writing a pretty basic program using Dev C++ and i'm using a seriesof IF statements to create a menu system. (i.e, choose 1 to edit this, choose 2 to edit this etc.) Annoyingly if i go into 1 "menu" and then return to main, i can't go back to the beginning. All it does is bring up the main 'menu' underneath all of the other things i have done. Can i 'wipe' the screen at all, or do i have to live with this?

    Another question. Using a system("PAUSE") function, can i get it to say anything other than "Press any key to continue"

    Cheers for your help.

    P.S If you need me to post code then i'll do that. Thanks

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    search the faq for "CLS"

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    5
    cheers for that. Any idea about the second point: the system("PAUSE") bit?

    It's not important but aesthetically speaking, it's quite a nice touch. Hehe

    Ta

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >can i get it to say anything other than "Press any key to continue"
    Write your own pause program that has the desired functionality, add it to the PATH, and say:
    Code:
    system ( "MYPAUSE" );
    My best code is written with the delete key.

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Here's some tips on clearing the screen:

    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    The use of system("PAUSE") has several problems, since system executes the string given to it as though it was a system command - in this case, it's executing PAUSE.exe or .com or something like that. Here are some details:

    http://www.cprogramming.com/tips/sho...ount=30&page=1

    Here are some alternatives:

    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    5
    Thanks for all that. When i use the getch() command it works, but kicks up a windows error, and claims that the .exe program needs to close. i've included <conio> but it still doesn't ;like it
    Is there something i need to include or do to accomodate the getch() command?

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    9
    Quote Originally Posted by caffrey
    Hey, i'm writing a pretty basic program using Dev C++ and i'm using a seriesof IF statements to create a menu system. (i.e, choose 1 to edit this, choose 2 to edit this etc.) Annoyingly if i go into 1 "menu" and then return to main, i can't go back to the beginning. All it does is bring up the main 'menu' underneath all of the other things i have done. Can i 'wipe' the screen at all, or do i have to live with this?

    Another question. Using a system("PAUSE") function, can i get it to say anything other than "Press any key to continue"

    Cheers for your help.

    P.S If you need me to post code then i'll do that. Thanks
    try
    Code:
    #include <stdio.h>    //For Standard Input/Output
    .

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Or you could use cstdio since this is c++ and not c

  9. #9
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    That particular solution (referring to conio.h) may actually be worse than what you were actually originally using. I apologize - I should've warned you about that. One of the reasons that system() should be avoided if possible is because the program you call might not always be there. conio.h is not part of the standard - it's just a nice addition that many compilers have. Play around with some of the other options.

    edit: and I'd assume that if he's using that library, he's already included it, Kilo.

  10. #10
    Registered User
    Join Date
    May 2005
    Posts
    5
    Once more, thanks but it still doen't like it. If i choose to Use

    Code:
      int ch;
      printf ("Press [Enter] to continue");
      while ((ch = getchar()) != '\n' && ch != EOF);
      goto: main;
    It executes this instantly and jumps me straight back to my main. Using a cheeky little goto: unfortunately

    What's going on? Any ideas? If i remove the goto then it just carries on through to the next section

  11. #11
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    If you're sure you want to use system("PAUSE"), try couting your pause message and then using
    system("PAUSE > nul") ... which should redirect the pause message to nul, aka Nowhere.

    For pausing, though, cin.get() (found in <iostream>) should be simpler and more universal...
    Last edited by Nazca; 05-02-2005 at 04:20 PM.

  12. #12
    Registered User
    Join Date
    May 2005
    Posts
    5
    Cheers NAzca, thats what i was after. No doubt i'll have more questions before my assignment is over!


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, 03:41 AM
  5. Clearing the screen
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 05-23-2002, 02:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21