C++ Basics — what is cout and cin?

Marika Lam
2 min readApr 11, 2022

1. cout

cout << "Output sentence"; // prints Output sentence on screen
cout << 120; // prints number 120 on screen
cout << x; // prints the value of x on screen
cout << "This " << " is a " << "single C++ statement" << endl;
  • It means standard output
  • On most program environments, the standard output by default is the screen
  • The << operator inserts the data that follows it into the stream that precedes it.
  • Multiple insertion operations (<<) may be chained in a single statement:
  • The endl manipulator produces a newline character, exactly as the insertion of '\n' does;

2. cin

  • In most program environments, the standard input by default is the keyboard, and the C++ stream object defined to access it is cin.
  • For formatted input operations, cin is used together with the extraction operator, which is written as >> (i.e., two "greater than" signs). This operator is then followed by the variable where the extracted data is stored. For example:
int age;
cin >> age;
  • The first statement declares a variable of type int called age, and the second extracts from cin a value to be stored in it.
  • This operation makes the program wait for input from cin; generally, this means that the program will wait for the user to enter some sequence with the keyboard. In…

--

--