streams

In a program supplied by a course instructor, the following function is called with:

ShowMenu() // (parameterless)

The (abridged) definition is as follows:

void ShowMenu(std::ostream& os = std::cout)
{
os << " ... \n"
<< " ... \n";
}

If the output is eventually to cout, why go through the trouble of creating an ostream object in the header, and why not just use

{
std::cout << " ... \n"
<< " ... \n";
}
Because you could theoretically want to print it to your custom stream, a file, to cerr, etc...
void ShowMenu(std::ostream& os = std::cout)
The bold part means that that parameter is a default parameter. Meaning that, if that parameter is not explicitly passed, os will default to std::cout.
Topic archived. No new replies allowed.