如何在控制台程序 (C++) 中上一行 [英] How to go up a line in Console Programs (C++)

查看:52
本文介绍了如何在控制台程序 (C++) 中上一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C++ 中,我试图返回一行以添加一些字符.到目前为止,这是我的代码:

In C++ I'm trying to go back up a line to add some characters. Here is my code so far:

cout << "\n\n\n\n\n\n\n\n\n\n\xc9\xbb\n\xc8\xbc"<<flush;
Sleep(50);

如您所见,我有 10 个换行符.在我的动画中,一个新块将从屏幕顶部落下.但我不知道如何返回这些行以添加我需要的字符.我试过 \r,但那不会做任何事情,而且 \b 也不会上升到前一行.另外,flush究竟是做什么的?我只用 C++ 编程了大约 2 天,所以我是新手 =P.

As you can see, I have 10 newline characters. In my animation, a new block will be falling from the top of the screen. But I don't know how to go back up those lines to add the characters I need. I tried \r, but that dosen't do anything and \b dosen't go up the previous line either. Also, what exactly does flush do? I've only been programming in C++ for about 2 days so I'm a newb =P.

非常感谢!!!

基督徒

推荐答案

如果您的控制台支持 VT100 转义序列(大多数都可以),然后你可以使用ESC [A,像这样:

If your console supports VT100 escape sequences (most do), then you can use ESC [ A, like this:

cout << "\x1b[A";

将光标向上移动一行.根据需要重复.

to move the cursor up one line. Repeat as necessary.

这篇关于如何在控制台程序 (C++) 中上一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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