C++ streams have several different manipulators that may be used to control both input and output, some of which have already been discussed. The most common manipulator is std::endl, which outputs a newline and then flushes the output stream:
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
}
> g++ -std=c++17 scratchpad.cpp; ./a.out
Hello World
Another way to write this same logic is to use the std::flush manipulator:
#include <iostream>
int main()
{
std::cout << "Hello World\n" << std::flush;
}
> g++ -std=c++17 scratchpad.cpp; ./a.out
Hello World
Both are the same, although '\n' should always be used unless a flush is explicitly needed. For example, if multiple lines are needed, the following is preferred:
#include <iostream>
int main()
{
std::cout...