使用C ++清除屏幕 [英] Clear Screen using C++

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

问题描述

我想清除CMD屏幕我已经看到了几个选项首先是

I would like to clear the CMD screen I have seen a few options first is

system('clr');  

但不想使用系统原因,那么它使它依赖于窗口,与unix版本

but dont want to use system cause then it makes it dependent on windows, same with the unix version

如果我尝试

cout << string(22, '\n');

然后我的下一行文本在屏幕的底部,我想它在顶部。如何清除屏幕并将文本返回到屏幕顶部?

then my next line of text is at the bottom of the screen and i want it at the top. How can I clear the screen and get the text back to the top of the screen?

因此,我有这个。

cout<<string(22, '\n');
cout<<"************Question 1 *******"<<endl;
cout<<"WHO WAS THE FIRST BLACK PRESEDENT?"<<endl;
cout<<"(1) Obama"<<endl;
cout<<"(2) Bush"<<endl;
cout<<"(3) Jordan" <<endl;
cin>>answer>>endl;

这将清除屏幕,然后把mymenu在屏幕的底部...

this will clear the screen then put mymenu at the bottom of the screen... how can i make it clear screen and put the question/answers back up top of screen.

推荐答案

试试这个:它可以在linux和windows上运行..

try this: it works both on linux and windows..

cout << "\033[2J\033[1;1H";

这是一个特殊的关键字,转换为屏幕清除。

this is a special keyword that translates as clearing of screen..

你可以将这个函数放在 clrscr()的函数上,具体取决于你的实现...

you can enclose this on a function like clrscr() depending on your implementation...

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

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