有没有办法更改已经写入控制台的内容?
例如,我想要更改已经写成的一行:
_ Foo..。要这样做:
+ Foo虽然理想情况下,这可以在Windows (powershell或命令行)和Linux (shell)上运行,但只支持Linux的解决方案是可以接受的。
我不熟悉标准输入和输出,所以如果这是一个基本问题,请原谅。
发布于 2018-04-24 09:55:55
如果光标仍在同一行上,则可以执行以下操作:
write("_ Foo");
stdout.fllush;//To force the displaying of the text now.
writeln("\r+ Foo"); //Output will be replaced但这是行不通的:
writeln("_ Foo"); //Equivalent to as `write("_ Foo\n");`
stdout.fllush;//To force the displaying of the text now
writeln("\r+ Foo"); //Output will not be replaced (it will be on new line).也可以执行此操作来逐个擦除字符:
write("_ Foo");
stdout.fllush;//To force the displaying of the text now
writeln("\b+ Foo"); //Output will be "_ Fo+ Foo"我还没有找到一种方法来擦除前面的行(我认为这是故意的)。
https://stackoverflow.com/questions/49989403
复制相似问题