简体   繁体   English

C++,在 Repl.it 中清除屏幕

[英]C++, Clear the screen in Repl.it

I'm using a website, repl.it, to program in C++.我正在使用网站 repl.it 用 C++ 进行编程。 I use the site because I often use a computer that can't download the software for c++.我使用该站点是因为我经常使用无法下载c++软件的计算机。 I'm trying to make a card game that display the contents of the cards on the console.我正在尝试制作一个在控制台上显示卡片内容的纸牌游戏。 I need to be able to write and delete information on the screen.我需要能够在屏幕上写入和删除信息。 The problem is that I don't know how to remove the written text.问题是我不知道如何删除书面文本。 I tried: std::cout << "\\b";我试过: std::cout << "\\b"; But that was kind of didn't work.但这有点行不通。 Can anyone please help me out?任何人都可以帮我吗?

For clearing the screen use system("clear") .清除屏幕使用system("clear") Here is an example.这是一个例子。

#include <iostream>
#include <cstdlib>

int main()
{
  std::cout << "Press any key to clear the screen.\n";
  std::cin.ignore();
  system("clear");
}

I found a solution.我找到了解决方案。 You can use ANSI escape codes.您可以使用 ANSI 转义码。 Here is a website that can explain the basics http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html It uses python but the codes are the same.这是一个可以解释基础知识的网站 http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html它使用python但代码相同。 To clear the screen: std::cout << "\";清除屏幕: std::cout << "\"; This works on Repl.it.这适用于 Repl.it。 sanitizedUser answers works too and is way simpler. sanitizedUser 答案也有效,而且更简单。 If you just want to clear the screen, I would prefer his method.如果你只是想清屏,我更喜欢他的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM