Input using stdin

N

Nikhil Warade

How can I give input to a program using STDIN
Suppose I want the program to take the value x=10
On some other site i found it as STDIN.read,but its not working.
 
F

Friedrich Dominicus

Nikhil Warade said:
How can I give input to a program using STDIN
Suppose I want the program to take the value x=10
On some other site i found it as STDIN.read,but its not working.

print("Give me a string ");
STDOUT.flush
a_string = gets
print("You gave me '#{a_string}'")

Regards
Friedrich
 
F

Friedrich Dominicus

Nikhil Warade said:
Please check http://codegolf.com/reverse where we need to input using
STDIN
You don't seem to have used STDIN
gets works on the standard input if you insist you can write
STDIN.gets if that makes you feel better


STDIN.public_methods.sort
=> ["<<", "==", "===", "=~", "__id__", "__send__", "all?", "any?",
"binmode", "class", "clone", "close", "close_read", "close_write",
"closed?", "collect", "detect", "display", "dup", "each", "each_byte",
"each_line", "each_with_index", "entries", "eof", "eof?", "eql?",
"equal?", "extend", "fcntl", "fileno", "find", "find_all", "flush",
"freeze", "frozen?", "fsync", "getc", "gets",
^^^^^^ here is your gets

Friedrich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,285
Messages
2,571,416
Members
48,107
Latest member
AmeliaAmad

Latest Threads

Top