Prefer '\n' over std::endl when outputting text to the console because std::end moves cursor to next line + flushes buffer
✅
Buffering & flushing
std::cout is buffered , meaning a buffer stores all cout until it is full then it will print the output all together into the terminal. increase efficiency as less operations to terminal.
Use std::flush to manually flush out the buffer to ensure immediate display
#include <iostream> // for std::cout
int main()
{
int x{ 5 };
std::cout << "x is equal to: " << x;
return 0;
}
// x is equal to: 5
std::cout << "Hi!" << std::endl; // std::endl will cause the cursor to move to the next line of the console
std::cout << "My name is Alex." << std::endl;
// Hi!
// My name is Alex.
std::cout << "x is equal to: " << x << '\n';
std::cout << "And that's all, folks!\n";