[英]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.