在 Xcode 中清除屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9348153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:20:52  来源:igfitidea点击:

Clear Screen in Xcode

c++xcodemacosconsole-application

提问by Nishay Naser

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?

我正在使用 C++ 在 Xcode 中制作图书馆管理系统。由于 Xcode 不支持诸如 conio.h 之类的库,并且系统“cls”在其中不起作用。当我希望它从一个菜单切换到另一个菜单时,我应该使用什么代码来清除屏幕?

回答by kamran

Check this out.

看一下这个。

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

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.

没有直接的方法可以做到这一点。该system()命令在 Mac (Unix) 上不起作用。一种选择是使用代码添加大量空格 ie\n 或其他方式是使用curses库 #include < curses.h >(curses.h)然后使用system("clear"),这基本上会做同样的事情。因此,最好使用代码而不是使用某些库来手动打印空格。

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

您还可以为基于 POSIX(Unix、Linux、Mac OSX 等)的系统做一件事 [注意:我自己没有测试过]:

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

你必须链接到正确的库(之一-lcurses-lterminfo等等)来编译最后一个。(来源:http: //www.cplusplus.com/forum/articles/10515/