【问题标题】:Clear the current line, as with fflush(stdout) in C [duplicate]清除当前行,与 C 中的 fflush(stdout) 一样 [重复]
【发布时间】:2014-08-10 07:49:55
【问题描述】:

我有一个很长的 for 循环,它会打印出很多行信息。我想将其保留为仅覆盖前几行的一行。我试过 Console.out.flush() 但它似乎不起作用。

【问题讨论】:

标签: c# console fflush


【解决方案1】:

使用

Console.SetCursorPosition

获取光标所在的位置

Console.CursorLeft
Console.CursorTop

例子

int i = 0;

Console.WriteLine("Numbers will count below this line");

int cLeft = Console.CursorLeft;
int cTop = Console.CursorTop;

while (true)
{
    Console.SetCursorPosition(cLeft, cTop);
    Console.WriteLine(i);
    i++;
}

【讨论】:

  • 还不确定它是否是答案 - 考虑编辑帖子以澄清您正在回答的问题的确切解释。请注意,我已经链接到完全相同的建议 - 目前尚不清楚 OP 在寻找什么,否则已经重复了。
  • @AlexeiLevenkov 既然 OP 已经接受了这个答案,我会说它 is 重复。
猜你喜欢
  • 2019-01-05
  • 2021-07-22
  • 1970-01-01
  • 1970-01-01
  • 2012-07-21
  • 2021-10-15
  • 2019-03-06
  • 2010-12-27
  • 1970-01-01
相关资源
最近更新 更多