Comparison of Programming Languages (basic Instructions) - Standard Stream I/O

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(, end=""») print(, 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:

    Society’s double behavioral standard for women and for men is, in fact, a more effective deterrent than economic discrimination because it is more insidious, less tangible. Economic disadvantages involve ascertainable amounts, but the very nature of societal value judgments makes them harder to define, their effects harder to relate.
    Anne Tucker (b. 1945)

    To me heaven would be a big bull ring with me holding two barrera seats and a trout stream outside that no one else was allowed to fish in and two lovely houses in the town; one where I would have my wife and children and be monogamous and love them truly and well and the other where I would have my nine beautiful mistresses on nine different floors.
    Ernest Hemingway (1899–1961)