std::endl is an output stream modifier to go to the next line and flush the stream's buffer.
#include <iostream>
int main()
{
//Go to next line and flush the std::cout buffer
std::cout << std::endl;
}
The code above is equivalent to the code below [2]:
#include <iostream>
int main()
{
//Go to next line
std::cout << '\n';
//Flush the std::cout buffer
std::cout.flush();
}
- [1] C++ Core Guidelines: SL.io.50: Avoid endl
- [2] Angelika Langer, Klaus Kreft. Standard C++ IOStreams and Locales. 1999. ISBN:0-321-58558-5. Chapter 1.2.4, section 'Manipulators', page 23
- [3] C++ Weekly - Ep7 Stop Using std::endl