Hello world/Standard error: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created with Java and C++)
 
(C)
Line 2: Line 2:


Show how to print a message to standard error by printing "Goodbye, World!" on that stream.
Show how to print a message to standard error by printing "Goodbye, World!" on that stream.

=={{header|C}}==
<c>#include <stdio.h>

int main()
{
fprintf(stderr, "Goodbye, ");
fputs("World!", stderr);

return 0;
}
</c>
=={{header|C++}}==
=={{header|C++}}==
<cpp>#include <iostream>
<cpp>#include <iostream>

Revision as of 21:56, 7 January 2009

Task
Hello world/Standard error
You are encouraged to solve this task according to the task description, using any language you may know.

A common practice in computing is to send error messages to a different output stream than normal text console messages. The normal messages print to what is called "standard output" or "standard out". The error messages print to "standard error". This separation can be used to redirect error messages to a different place than normal messages.

Show how to print a message to standard error by printing "Goodbye, World!" on that stream.

C

<c>#include <stdio.h>

int main() { fprintf(stderr, "Goodbye, "); fputs("World!", stderr);

return 0; } </c>

C++

<cpp>#include <iostream>

using std::cerr; using std::endl;

int main () {

 cerr << "Goodbye, World!" << endl;
 return 0;

}</cpp>

Java

<java>public class Err{

  public static void main(String[] args){
     System.err.println("Goodbye, World!");
  }

}</java>