C ++ / XCode中的清除屏幕 [英] Clearing Screen in C++/XCode

查看:360
本文介绍了C ++ / XCode中的清除屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用XCode编写一个类的C ++程序。我想做的事情之一是简单地清除屏幕。我研究了如何做到这一点,但是,抓住的是,代码需要在Windows和Macintosh计算机上运行。我看了一些其他类似的问题,但没有答案帮助我。我知道没有屏幕,但我想要系统清除输出窗口。我知道命令 system(clear); 做我想要的,但是当XCode测试程序,而不是清除屏幕打印 TERM未设置变量

I am trying to write up a C++ program for a class using XCode. One of the things I wish to do, is to simply clear the screen. I've looked into how to do this, however the catch is that the code needs to run on both a Windows and Macintosh computer. I've looked at some other similar questions, but none of the answers help me. I know there is no "screen" but I want the system to clear the output window. I know that the command system("clear"); does what I want it to, but when XCode tests the program, instead of clearing the screen it prints TERM Variable not set

我试过打开终端并键入 clear 它实际上是以我想要的方式响应,所以为什么XCode里面的'终端'不做同样的事情?我只想得到XCode中的输出窗口来响应清除,就像终端已经做的那样。

I've tried opening up the terminal and typing clear and it does in fact respond the way I want it to, so why doesn't the 'terminal' inside of XCode do the same? I just want to get the output window in XCode to respond to clear the same way that the terminal already does.

这是我已经尝试的;

我去了终端,并运行 echo $ TERM 终端响应 xterm-256color 。然后我转到XCode并打开Scheme设置,并在Arguments下找到了一个Environment Variables设置。我添加了一个名为 TERM 的变量(空白列表),并赋值为 xterm-256color 。再次运行程序时,输出在输出窗口中显示¿[H¿[2J ],位于 TERM变量未设置用于打印。

I went to the terminal and ran echo $TERM, to which the terminal responded xterm-256color. I then went over to XCode and opened the "Scheme" settings, and found an Environment Variables setting under "Arguments". I added a variable (to the blank list) called TERM and gave it value xterm-256color. Upon running the program again, the output displays ¿[H¿[2J in the output window, positioned where the TERM Variable not set used to be printed.

最后,作为提醒,我不能按照现在的方式更改源代码,

Last thing, as a reminder, I cannot change the source code from the way it is now, or it could cause errors when the program is run on a Windows machine.

推荐答案

它不工作,因为你是说谎 :Xcode中的终端不是 xterm-256color ,而是 dumb 终端。更准确地说,显示代表 NSTextStorage 收集 stdout 和/或(根据目标交换机) stderr

It does not work because you are "lying": The terminal in Xcode is not a xterm-256color, but it is dumb terminal. More precise, the display represents a NSTextStorage that collects stdout and/or (depending on target switch) stderr.

哑终端无法清洁显示器。如果您想更改此设置,可以编写类似于 Xcode-Colors 的插件以了解ansi颜色代码。

A dumb terminal is not able to clean the display. If you want to change this, you can write a plug-in similar to Xcode-Colors what adds the ability to understand ansi color codes.

但是,如果你要求代码在Windows和OSX上运行,你可以坚持使用你的解决方案 system clear),因为它在正常OSX终端中正常工作。

However, if your requirement that the code simply run at Windows and OSX, you may stick with your solution system("clear"), since it works prefectly in the "normal" OSX terminal.

这篇关于C ++ / XCode中的清除屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆