Zack Zeng
Zack Zeng

Reputation: 81

Cannot use system("cls"); in Xcode in mac

I tried to execute

system (cls):

in Xcode in mac, but it doesn't work.

Upvotes: 2

Views: 12219

Answers (1)

StilesCrisis
StilesCrisis

Reputation: 16300

Two problems.

1 - You didn't use quotes.

2 - The command on OS X is clear, not cls.

system("clear");

Instead of doing that, a better way is to add these #includes and also this ClearScreen function which sends the terminal a clear command directly, instead of starting a separate process. Cribbed from http://www.cplusplus.com/articles/4z18T05o/#POSIX

#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" ) );   
}

Upvotes: 4

Related Questions