Read text from standard input

From CodeCodex

Implementations[edit]

C++[edit]

#include <iostream>
#include <string>
std::string line;
std::getline(std::cin, line);
std::cout<<"You entered: "<<line<<std::endl;

Common Lisp[edit]

(progn (write-string "> prompt ") (read-line))
> prompt fooey
"fooey" ;
NIL

Haskell[edit]

Prelude> do putStr "> prompt "; getLine
> prompt fooey
"fooey"

Java[edit]

    try {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String str = "";
        while (str != null) {
            System.out.print("> prompt ");
            str = in.readLine();
            process(str);
        }
    } catch (IOException e) {
    }

OCaml[edit]

# Printf.printf "> prompt %!";
  read_line();;
> prompt fooey
- : string = "fooey"

Python[edit]

s = raw_input('prompt> ')
print s

Ruby[edit]

line = gets
puts line