Reputation: 1802
It's a similar question that Read a single char from stdin without pressing enter
How do I read whole lines with crystal-lang ? I assume to use following Ruby equivalent code:
lines = $stdin.read
lines.each{|line| puts line}
Upvotes: 2
Views: 1069
Reputation: 66771
Apparently the equivalent of read
is STDIN.gets_to_end
FWIW.
https://groups.google.com/forum/#!topic/crystal-lang/O4DExFHJc5E
Upvotes: 0
Reputation: 1802
To use this code with online compiler
I just used STDIN directly
STDIN.each_line do |line|
puts line
end
Upvotes: 1
Reputation: 3175
Again, you use STDIN.raw
but this time you want to fetch a whole line at a time using IO#gets
. The easiest way to do that is this:
while line = STDIN.raw &.gets
puts line
end
Alternatively you could do this:
STDIN.raw do |stdin|
stdin.each_line do |line|
puts line
end
end
Upvotes: 2