Search:
Forum
General C++ Programming
streams
streams
May 3, 2009 at 10:20pm UTC
VictorH
(41)
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";
}
May 3, 2009 at 10:53pm UTC
firedraco
(6246)
Because you could theoretically want to print it to your custom stream, a file, to cerr, etc...
May 4, 2009 at 12:32am UTC
helios
(17607)
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.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs