Just make a function template:
template<typename T>
void printLn(T const & v, std::ostream & os = std::cout)
{
os << v << std::endl;
}
If you wanna get fancy with it and allow multiple arguments, and C++11 is available to you:
void printLn(std::ostream & os)
{
os << std::endl;
}
template<typename T, typename... Args>
void printLn(std::ostream & os, T const & v, Args&&... args)
{
os << v;
printLn(os, std::forward<Args>(args)...);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…