Standard IO refers to input and output from the terminal, with no GUI. The standard namespace refers to our window. This is the usual launch point for learning how to program.

C

printf("%.*s", strlen, buf); // allows certain bytes to be printed out

C++

C++ abstracts IO with streams. We have two standard lines. One is a header file, and the other sets our output namespace as the standard namespace.

#include <iostream>
using namespace std;

The << operator outputs things, and the >> operator takes things in. endl will output a new line character, it flushes things out. A handy tip for the >> and << operators:

  • When we print, the arrows point towards the left <<.
  • When we input, the arrows point right >>.
  • The arrows point in the direction of the data.
string name;
cin >> name;
cout << "Hello " << name << endl;

We have helpful functions that let us detect and handle input failures:

  • cin.fail() — returns true if any error occurs. cin is some object with an error-state flag. If fail() is true, then cin.ignore() will fail too.
    • So we need to cin.clear() before we cin.ignore().
  • cin.eof() — returns true if the end of the file is reached
  • cin.clear() will clear any error flags (if true).
  • cin.ignore(int n, char ch) — discards n characters or up to character ch.

Within the iostream library, we have a class called ostream (for the output stream). cout is an object of the ostream class. The cerr output stream is unbuffered.

JavaScript

The main way to print to the terminal is using console.log.

See also