====== Standard Output ======
Comparison of how different languages do screen output. Many languages have different calls for plain output, along with a second call that creates a [[http://en.wikipedia.org/wiki/Newline|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.
===== Language: BASIC =====
PRINT "Hello world"; : REM No newline
PRINT "Hello world" : REM Newline
<\/code>
===== Language: C =====
- include <stdio.h>
printf("Hello world!"); printf("Hello world!n"); <\/code>
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.");
<\/code>
===== Language: C++ =====
- include
using namespace std;
cout << "Hello world!"; cout << "Hello world!" << endl; <\/code>
===== Language: Java =====
System.out.print("Text");
System.out.println("Entire Line of Text");
<\/code>
===== Language: Pascal =====
Pascal uses single quotes for strings.
write('Hello World!');
writeln('Hello World!');
<\/code>
===== Language: Perl =====
Print with new line.
- !/usr/bin/perl
print "Hello Worldn"; <\/code>
===== Language: PHP =====
You can either use print.
print "Brought to you by PHP.";
print("Brought to you by PHP.");
<\/code>
Or echo which is slightly faster.
echo "Some text here.";
echo ("Some text here.");
<\/code>
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 textn");
<\/code>
===== Language: Python =====
print "Hello world!"
<\/code>
===== Language: Ruby =====
puts "Text" # adds a newline character at the end
print "Text" # does not add a newline character at the end
<\/code>
===== Language: Tcl =====
puts -nonewline "Hello "
puts "world!"
<\/code>
===== See Also ===== [[Standard|input]]
[[Standard|error]]