What is iostream

beginner c++11 containers

In C++ iostream means “input output stream” and it is the standard library for reading input and writing output from your program. To write output you use the standard cout, stream that is available everywhere in your program and shift values into cout with the left shift operator (<<).

#include <iostream>

int main() {
  std::cout << "Hello iostream.\n";
}
Hello iostream.

Reading Input

To read input you use the standard cin stream that is also available everywhere in your program and shift values out of cin with the right shift operator (>>).

#include <iostream>

int main() {
  int n = 0;
  std::cout << "Enter a number: ";
  std::cin >> n;
  std::cout << "You entered " << n << "\n";
}
Enter a number: You entered 42

For more C++ By Example, click here.