Clear Screen in Xcode

13,788

Check this out.

https://discussions.apple.com/thread/1064635?start=0&tstart=0

There is no direct way to do that; the system() command will not work on Mac (Unix). One option is to add a lot of spaces using code i.e.\n or other way is to use curses library #include < curses.h > (curses.h) and then use system("clear"), which basically will do the same thing. So, its better to print spaces manually using the code rather than using some library.

One more thing you can do for POSIX (Unix, Linux, Mac OSX, etc) based systems [Note: I have not tested it myself]:

#include < unistd.h >
#include < term.h >
void ClearScreen()
{
  if (!cur_term)
  {
     int result;
     setupterm( NULL, STDOUT_FILENO, &result );
     if (result <= 0) return;
  }
  putp( tigetstr( "clear" ) );
}

You'll have to link to the proper library (one of -lcurses, -lterminfo, etc.) to compile that last one. (Source: http://www.cplusplus.com/forum/articles/10515/)

Share:
13,788

Related videos on Youtube

Nishay Naser
Author by

Nishay Naser

Updated on June 04, 2022

Comments

  • Nishay Naser
    Nishay Naser almost 2 years

    I am making a Library Management System in Xcode using C++. As Xcode does not support libraries such as conio.h and system "cls" does not work in it. What code should I use to clear the screen when I want it to shift from one menu to the other?

    • Matthias Bauch
      Matthias Bauch over 12 years
      are you talking about a command line application (that you just write and launch from within Xcode)? Or a Xcode-plugin? Your question is not very clear, to me at least.
    • molbdnilo
      molbdnilo over 12 years
      @Nishay: man system says "#include <stdlib.h>". man is what we used before there were stackoverflows and googles on the internets, and it still works.