清除Xcode中的屏幕 [英] Clear Screen in Xcode
问题描述
我正在使用C ++在Xcode中制作一个图书馆管理系统.由于Xcode不支持诸如conio.h之类的库,因此系统"cls"在其中不起作用.想要从一个菜单切换到另一个菜单时,应该使用什么代码清除屏幕?
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?
推荐答案
检查一下.
https://discussions.apple.com/thread/1064635? start = 0& tstart = 0
没有直接的方法可以做到这一点; system()
命令在Mac(Unix)上不起作用.一种选择是使用代码添加大量空格,即\ n或其他方式是使用curses库
#include < curses.h >
(curses.h),然后使用system("clear")
,这基本上会做同样的事情.因此,最好使用代码而不是使用某些库手动打印空间.
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.
对于基于POSIX(Unix,Linux,Mac OSX等)的系统,您还可以做另一件事[注:我自己尚未对其进行测试]:
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" ) );
}
您必须链接到适当的库(-lcurses
,-lterminfo
等之一),以编译最后一个库. (来源: http://www.cplusplus.com/forum/articles/10515/)
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/)
这篇关于清除Xcode中的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!