I want to have a function that outputs certain pieces of information to a specific designated source that is inputted to the function. In code, what I mean is:
function output( source ) {
source << "hello" << endl;
}
where source can be a ofstream
or cout
. So that I can call this function like so:
output(cout)
or ofstream otp ("hello"); output(otp)
My question is, how do I characterize source
to make this work? It's fair to assume that source
will always be a member of the std
class
Thanks!
void output(std::ostream &source) {
source << "hello" << std::endl;
}
or even:
template <T>
void output(T &source) {
source << "hello" << std::endl;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With