Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 覆盖consle中的当前行(相当于python“r”)_C#_Stdout - Fatal编程技术网

C# 覆盖consle中的当前行(相当于python“r”)

C# 覆盖consle中的当前行(相当于python“r”),c#,stdout,C#,Stdout,在Python中,我将使用以下命令用新文本覆盖当前行: import sys sys.stdout.write('\r[Test]: Testing') 但我在C中如何做到这一点?我已经尝试过: Console.WriteLine("\r[This is a test]"); Console.WriteLine("\r[This the next stage]"); 但此代码在新行上写入,而不是覆盖同一行。等效代码为: Console.Write(“\r[Test]:Testing”);

在Python中,我将使用以下命令用新文本覆盖当前行:

import sys
sys.stdout.write('\r[Test]: Testing')
但我在C中如何做到这一点?我已经尝试过:

Console.WriteLine("\r[This is a test]");
Console.WriteLine("\r[This the next stage]");

但此代码在新行上写入,而不是覆盖同一行。

等效代码为:

Console.Write(“\r[Test]:Testing”);

Console.WriteLine将在打印字符串后添加新行。

如果您指明了要完成的任务,则会有所帮助。如果您试图发出新行,则它取决于平台。对于windows,您必须具有
\r\n
。具体来说,什么“不起作用”?@JonathanWood我认为目标是覆盖前面的字符串,因此,
\r\n
使用是错误的。可能是@JonathanWood的重复,如果您正在编写一个文件,并使用一个只知道如何处理特定新行分隔符的程序读取它,则可能是。