#Concept #Study #CPP
## cout
A simple output using `cout` from `std` namespace is used to output something to the console when running a program.
```c++
#include <iostream>
using namespace std;
int main(){
cout << "Hello world!" << endl;
return 0;
}
// Console Output:
/*
Hello World!
*/
```
`endl` at the end of a cout line will flush the current buffer, this is usually only done at the very beginning, for a more efficient use `\n` is used for a new line.
```c++
cout << "Hello world!\n";
cout << "Hello world!" << endl;
// Console Output:
/*
Hello World!
Hello World!
*/
```
Variables can also be output with cout:
```c++
int number1 = 12;
cout << "Hello world!\n";
cout << "Your number is: " << number1 << endl;
// Console Output:
/*
Hello World!
Your number is: 12
*/
```
## cin
`cin` is used inside c++ to store input from the user inside a buffer, which is then assigned to a variable.
Whitespaces and other types of input that are not part of the variable where the input is stored into are ignored.
When asking for 2 integers with `cin`, and you enter `100 200` both of the cin will be automatically fill both variables, as the first one only takes the `100`
and stops at the whitespace, the 2nd cin will take the remaining `200` integer.
```c++
#include <iostream>
using namespace std;
int main(){
int num1;
cout << "Input integer:" << endl;
cin >> num1;
return 0;
}
// Console Output:
/*
Input integer:
*/
```
multiple `cin` can also be chained, which will take 2 inputs, like this:
```c++
cin >> num1 >> num2;
```
## 🔗Resources