Standard Stream I/O
read from | write to | ||
---|---|---|---|
stdin | stdout | stderr | |
ALGOL 68 | readf(($format$, x)); or getf(stand in, ($format$, x)); |
printf(($format$, x)); or putf(stand out, ($format$, x)); |
putf(stand error, ($format$, x)); |
C (C99) | scanf(format, &x); or fscanf(stdin, format, &x); |
printf( format, x); or fprintf(stdout, format, x); |
fprintf(stderr, format, x ); |
Objective-C | data = readDataToEndOfFile]; | writeData:data]; | writeData:data]; |
C++ | «std::»cin >> x; or «std::»getline(«std::»cin, str); |
«std::»cout << x; | «std::»cerr << x; or «std::»clog << x; |
C# | x = Console.Read; or x = Console.ReadLine; |
Console.Write(«format, »x); or Console.WriteLine(«format, »x); |
Console.Error.Write(«format, »x); or Console.Error.WriteLine(«format, »x); |
D | x = std.stdio.readln | std.stdio.write(x) or std.stdio.writeln(x) or std.stdio.writef(format, x) or std.stdio.writefln(format, x) |
stderr.write(x) or stderr.writeln(x) or std.stdio.writef(stderr, format, x) or std.stdio.writefln(stderr, format, x) |
Java | x = System.in.read; or x = new Scanner(System.in).nextInt; or x = new Scanner(System.in).nextLine; |
System.out.print(x); or System.out.printf(format, x); or System.out.println(x); |
System.err.print(x); or System.err.printf(format, x); or System.err.println(x); |
Go | fmt.Scan(&x) or fmt.Scanf(format, &x) or x = bufio.NewReader(os.Stdin).ReadString('\n') |
fmt.Println(x) or fmt.Printf(format, x) |
fmt.Fprintln(os.Stderr, x) or fmt.Fprintf(os.Stderr, format, x) |
JavaScript |
document.write(x) | ||
JavaScript |
Response.Write(x) | ||
JavaScript |
x = WScript.StdIn.Read(chars) or x = WScript.StdIn.ReadLine |
WScript.Echo(x) or WScript.StdOut.Write(x) or WScript.StdOut.WriteLine(x) |
WScript.StdErr.Write(x) or WScript.StdErr.WriteLine(x) |
Common Lisp | (setf x (read-line)) | (princ x) or (format t format x) |
(princ x *error-output*) or (format *error-output* format x) |
Scheme (R6RS) | (define x (read-line)) | (display x) or (format #t format x) |
(display x (current-error-port)) or (format (current-error-port) format x) |
ISLISP | (setf x (read-line)) | (format (standard-output) format x) | (format (error-output) format x) |
Pascal | read(x); or readln(x); |
write(x); or writeln(x); |
|
Visual Basic | Input« prompt,» x | Print x or ? x |
|
Visual Basic .NET | x = Console.Read or x = Console.ReadLine |
Console.Write(«format, »x) or Console.WriteLine(«format, »x) |
Console.Error.Write(«format, »x) or Console.Error.WriteLine(«format, »x) |
Python 2.x | x = raw_input(«prompt») | print x or sys.stdout.write(x) |
print >> sys.stderr, x or sys.stderr.write(x) |
Python 3.x | x = input(«prompt») | print(x«, end=""») | print(x«, end=""», file=sys.stderr) |
S-Lang | fgets (&x, stdin) | fputs (x, stdout) | fputs (x, stderr) |
Fortran | READ(*,format) variable names or READ(INPUT_UNIT,format) variable names |
WRITE(*,format) expressions or WRITE(OUTPUT_UNIT,format) expressions |
WRITE(ERROR_UNIT,format) expressions |
Forth | buffer length ACCEPT ( # chars read ) KEY ( char ) |
buffer length TYPE char EMIT |
|
PHP | $x = fgets(STDIN); or $x = fscanf(STDIN, format); |
print x; or echo x; or printf(format, x); |
fprintf(STDERR, format, x); |
Perl | $x = <>; or $x = |
print x; or printf format, x; |
print STDERR x; or printf STDERR format, x; |
Perl 6 | $x = $*IN.get; | x.print or x.say |
x.note or $*ERR.print(x) or $*ERR.say(x) |
Ruby | x = gets | puts x or printf(format, x) |
$stderr.puts(x) or $stderr.printf(format, x) |
Windows PowerShell | $x = Read-Host«« -Prompt» text»; or $x = ::Read; or $x = ::ReadLine |
x; or Write-Output x; or echo x |
Write-Error x |
OCaml | let x = read_int or let str = read_line or Scanf.scanf format (fun x ... -> ...) |
print_int x or print_endline str or Printf.printf format x ... |
prerr_int x or prerr_endline str or Printf.eprintf format x ... |
F# | let x = System.Console.ReadLine | printf format x ... or printfn format x ... |
eprintf format x ... or eprintfn format x ... |
Standard ML | val str = TextIO.inputLIne TextIO.stdIn | print str | TextIO.output (TextIO.stdErr, str) |
Haskell (GHC) | x <- readLn or str <- getLine |
print x or putStrLn str |
hPrint stderr x or hPutStrLn stderr str |
^a Algol 68 additionally as the "unformatted" transput routines: read, write, get and put.
^b gets(x) and fgets(x, length, stdin) read unformatted text from stdin. Use of gets is not recommended.
^c puts(x) and fputs(x, stdout) write unformatted text to stdout.
^d fputs(x, stderr) writes unformatted text to stderr
^e INPUT_UNIT, OUTPUT_UNIT, ERROR_UNIT are defined in the ISO_FORTRAN_ENV module.
Read more about this topic: Comparison Of Programming Languages (basic Instructions)
Famous quotes containing the words standard and/or stream:
“Liberty requires opportunity to make a livinga living decent according to the standard of the time, a living which gives a man not only enough to live by, but something to live for.”
—Franklin D. Roosevelt (18821945)
“In contrast to the flux and muddle of life, art is clarity and enduring presence. In the stream of life, few things are perceived clearly because few things stay put. Every mood or emotion is mixed or diluted by contrary and extraneous elements. The clarity of artthe precise evocation of mood in the novel, or of summer twilight in a paintingis like waking to a bright landscape after a long fitful slumber, or the fragrance of chicken soup after a week of head cold.”
—Yi-Fu Tuan (b. 1930)