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.


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

C Edit

#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++ Edit

#include <iostream>

using namespace std;

cout << "Hello world!";

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

Haskell Edit

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

C# Edit

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.


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

Java Edit

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

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

OCaml Edit

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

Pascal Edit

Pascal uses single quotes for strings.

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

Perl Edit

Print with new line.


print "Hello World\n";

PHP Edit

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 Edit


print "Hello world!"


print("Hello world!")

Ruby Edit

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

Tcl Edit

puts -nonewline "Hello "
puts "world!"

See Also Edit

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.