Clear Screen in Xcode

﹥>﹥吖頭↗ 提交于 2019-12-08 06:52:42

问题


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?


回答1:


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/)



来源:https://stackoverflow.com/questions/9348153/clear-screen-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!