code
16px-Pencil

The standard output is a stream where console-based programs output lines of text.

Comparison of how different languages do screen output. Many languages have different calls for plain output, along with a second call that creates a new line.

The advantage to using console output is that it's usually very fast and can be redirected to other applications, pipes, or files.

BASIC

PRINT "Hello world"; : REM No newline
PRINT "Hello world" : REM Newline

C

#include <stdio.h>

printf("Hello world!");
printf("Hello world!\n");

The printf function takes a format string and an arbitrary number of additional parameters that supply values to the string. For instance, %s indicate a string, %d a numeric, %c a character, and so forth. Between these flags numerical arguments indicate field with, precision, and justification.

For simply printing a string as-is, with a newline automatically appended at the end:

puts("Hello world.");

C++

#include <iostream>

std::cout << "Hello world!";

std::cout << "Hello world!" << std::endl;
std::cout << "Hello world! \n";

Haskell

do putStr "Hello world!"
   putStrLn "Hello world!"
   print 42


C#

Console.WriteLine("Hello world!");
Console.Write("Hello world!");

The function "Write" will write the specified to text to the output stream, WITHOUT a new line, where as the "WriteLine" function WILL go to the next line.

VB.NET

Console.WriteLine("Hello world!")
Console.Write("Hello world!")

Java

The System.out object (of type PrintStream) represents the standard output in Java.

 System.out.print("Text");
 System.out.println("Entire Line of Text");

OCaml

print_string "Hello world!";
print_endline "Hello world!";
Printf.printf "Hello world!\n";

Pascal

Pascal uses single quotes for strings.

write('Hello World!');
writeln('Hello World!');

Perl

Print with new line.

#!/usr/bin/perl

print "Hello World\n";

PHP

You can either use print.

print "Brought to you by PHP.";
print("Brought to you by PHP.");

Or echo which is slightly faster.

echo "Some text here.";
echo ("Some text here.");

With both, if you use single quotes, the string will be taken literally. Whereas, with double quotes (above) variables and special characters will be expanded. For example, to write something with a newline at the end:

print("This is one line of text\n");

When using PHP in CLI mode (Command line interface), you can explicitly write in stdout:

$stdout = fopen('php://stdout', 'w'); // opens stdout in write mode
fputs($stdout, 'Hello World!'); // writes Hello World

Python

2.x

print "Hello world!"

3.x

print("Hello world!")

Ruby

puts "Text" # adds a newline character at the end
print "Text" # does not add a newline character at the end

Tcl

puts -nonewline "Hello "
puts "world!"

See Also