Difference between revisions of "Read text from standard input"

From CodeCodex

(OCaml)
Line 16: Line 16:
 
===OCaml===
 
===OCaml===
 
<pre>
 
<pre>
# print_string "> prompt";
+
# Printf.printf "> prompt %!";
 
   input_line stdin;;
 
   input_line stdin;;
fooey
+
> prompt fooey
> prompt- : string = "fooey"
+
- : string = "fooey"
 
</pre>
 
</pre>
 
[[Category:Java]]
 
[[Category:Java]]
 
[[Category:I/O]]
 
[[Category:I/O]]
 
[[Category:Objective Caml]]
 
[[Category:Objective Caml]]

Revision as of 13:09, 18 August 2006

Implementations

Java

    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

# Printf.printf "> prompt %!";
  input_line stdin;;
> prompt fooey
- : string = "fooey"