5 Replies Latest reply: Oct 14, 2007 12:56 PM by Steve Herman1
Lady777 Level 1 Level 1 (0 points)
In Turbo C, I use #include <conio.h> then clrscr () to clear the screen in C. I asked a few people how to do it in C++ and they told me to use system("cls")with #include <iostream>. I tried that but it's not working in Xcode. I think those commands will only work if used with other compilers. So how do you clear the screen in Xcode? Please give me the C and C++ commands as well as the libraries that I need to include. Thank you!!!

PowerBook G4, Mac OS X (10.4.10), 1 GB RAM
  • etresoft Level 7 Level 7 (25,525 points)
    You want to use the ncurses library. Just include the curses.h system file. Then, call the "clear" function.

    The conio functions are only for PCs. MacOS X and all other Unix systems use the termio interface. The curses library make that terminal interface somewhat easier to use. It's use isn't very common these days because most people write Cocoa (or Qt or Java) user interfaces.
  • andlabs Level 2 Level 2 (170 points)
    Sorry for resurrecting the dead, but on UNIX systems the command is clear:

    system("clear")
  • MrHoffman Level 6 Level 6 (12,980 points)
    FWIW, the clear() call is portable.

    The system("clear") or system("cls") approach isn't. On another platform, the direct equivalent is system("type/page nl:"), FWIW.

    Porting code that uses system() can get ugly, as it is dependent on the particular shell, and some shells can differ widely and wildly.

    I've also seen cases where the created process and the parent process displays can conflict; if the parent is using a curses library, then it's usually best to use curses (directly) to clear the display. Scrolling regions on classic terminals and older applications might not be commonly seen, but they do exist. And they can send a system("clear") into the weeds.
  • Lady777 Level 1 Level 1 (0 points)
    I typed #include <curses.h> and system("clear"); and I got this:
    TERM environment variable not set.

    When I typed #include <curses.h> and system("cls");, I got this:
    sh: line 1: cls: command not found

    When I typed #include <curses.h> and clear();, I got this:
    ZeroLink: unknown symbol '_clear'

    I don't know what I missed.
  • Steve Herman1 Level 4 Level 4 (2,545 points)
    Lady777 wrote:
    I typed #include <curses.h> and system("clear"); and I got this:
    TERM environment variable not set.


    I think this is because Xcode's run log window doesn't normally set the TERM environment variable. I haven't been able to get any screen clearing commands to work in Xcode's run log window so I don't think it acts like a true terminal window. However system("clear") should work in Terminal.app. By the way, calling system() doesn't require curses.


    When I typed #include <curses.h> and system("cls");, I got this:
    sh: line 1: cls: command not found


    Because "cls" is not a valid command in OS X... "clear" is though.


    When I typed #include <curses.h> and clear();, I got this:
    ZeroLink: unknown symbol '_clear'


    Because you didn't link with the curses library... refer to your other thread. Linking with curses and calling clear(); doesn't work for me in Xcodes run log or in Terminal. It runs but it doesn't clear the window. But I'm not familiar with using curses so I could certainly be doing something wrong.

    Steve

    Message was edited by: Steve Herman1