0
a=gets.to_i
b=gets.to_i

this code gets input like this
2
2
but in c++ std::cin will get input after space or \n
So how do I make ruby get input like std::cin
I am new to ruby and can not find the answer on google so help would be appreciated thanks

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by fk123
0

You could always just get the entire line and split it up by spaces:

line = gets
return unless line
line.chomp.split(/\s+/).each do |token|
   puts "Token: #{token}"
end

which will give you something like:

1 2 3 4 5 # this is the input
Token: 1
Token: 2
Token: 3
Token: 4
Token: 5
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.