简体   繁体   English

我写东西后想在consol中有第一行..我怎么能得到?

[英]I want to have first row in consol after i write something.. how can i get?

During programming, I just want to first row in console for example: 在编程期间,我只想在控制台中第一行,例如:

First step: (in console result) 第一步:(在控制台结果中)

a

a

a

a

a

// this program maybe like this
 for(int i=0;i<5;i++)
    cout<<"a"<<endl;

Second step: This part is what I ask, I want to get the form below (in console): 第二步:这是我要问的部分,我想获得下面的表格(在控制台中):

ab

ab

ab

ab

ab

Exactly what I want is after first step, I can't return to first row just I want to write 'b' but what I know is I can't be back to first row. 正是我想要的是第一步之后,我无法回到第一行,而只是想写“ b”,但是我知道我无法回到第一行。

So how can I do? 那我该怎么办?

you can't modify a console line afterwards. 之后,您将无法修改控制台行。 to give the impression that you do you may clear the console and then rewrite the whole output. 为了给您留下印象,您可以清除控制台,然后重写整个输出。

You can use control sequences if your terminal supports. 如果您的终端支持,则可以使用控制序列 For instance, you can try the following codes: 例如,您可以尝试以下代码:

int main() {
    for (int i = 0; i < 5; i++) {
        cout << 'a' << endl;
    }

    cout << '\033' << "[5A"; // move the cursor 5 cells up
    cout << '\033' << "[1C"; // 1 cells forward
    for (int i = 0; i < 5; i++) {
        cout << 'b';
        cout << '\033' << "[1D"; // 1 cells down
        cout << '\033' << "[1B"; // 1 cells back
    }
    return 0;
}

暂无
暂无

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

相关问题 我如何在C ++文件的末尾写一些东西到文件 - How can i write something to file at the end of the file in c++ 如何让OpenGL在所需位置绘制字符? - How can I get OpenGL to draw the character at the location I want? 我怎样才能得到句子而不是单词? 我想通过 c++ 中的 strstr 搜索第一个字符串中的第二个字符串 - How can i get sentence instead of word? i want to search second string in first string by strstr in c++ 我有一堆要向用户隐藏的模板参数。 我怎样才能做到这一点? - I have a bunch of template parameters that I want to hide from my users. How can I do this? 当我想要捕捉外面的东西时,无法编译lambda - Can't compile lambda when I want to catch something outside 我有一个指向自定义项目的未初始化指针表,我想检查是否已经存在某些东西 - I have a table of un-initialized pointers to custom items that I want to check if there exists something already 我可以在make_tuple中编写使用类型推导的东西吗? - Can I write something that uses type deduction as in make_tuple? 我无法显示文件的第一行 - i can't display the first row of the file 如何通过引用弹出内容? - How can I pop something by reference? 我想编写一个 c++ 程序,其中有一个文件,我想看看文件中出现了多少次“好”这个词。 为什么这不起作用 - I want to write a c++ program in which I have a file and I want to see how many times the word "good" appears in the file. Why does this not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM