[英]What's the equivalent of ruby print + $stdout.flush in elixir
I can't find how to refresh a single line of output with Elixir. 我找不到如何用Elixir刷新一行输出。
In Ruby we can do this : 在Ruby中,我们可以这样做:
n = 0
loop do
print n
$stdout.flush
n += 1
end
But what should I use to do the same with Elixir ? 但是我应该如何对Elixir进行同样的处理?
Use IO.write/1
. 使用
IO.write/1
。 There's no need to manually flush stdout as far as I can see. 据我所知,无需手动刷新标准输出。 The following code writes 1 to 10 in a single line with a 1 second delay between each number.
以下代码在一行中写入1到10,每个数字之间有1秒的延迟。 stdout is flushed automatically after each write.
每次写入后都会自动刷新stdout。
for i <- 1..10 do
IO.write i
:timer.sleep(1000)
end
Output: 输出:
12345678910
(With a 1 second delay between each number.) (每个数字之间有1秒的延迟。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.