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

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

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.