In C++ there is a standard library function called cout, which lets me send text to the console. I am sure you know that.
#include <iostream>
using std::cout;
cout << "Some Text " << 15 << " Other Text";
To do a linebreak at the end, I need to use endl.
cout << "Some Text " << 15 << " Other Text" << endl;
How can I write a function named coutl which behaves like cout but also adds a likebreak? I want to use the same syntax that cout uses, especially the << operator.
coutl << "Some Text " << 15 << " Other Text"; // coutl should add a linebreak
By creating a little proxy object which adds
<< endlin its destructor:Then you need a function so that you will get a temporary:
This should then work:
UPDATE:
I move the destructor which adds a
std::endlto an inner object owned by astd::shared_ptr<>so that the example doesn’t depend on Copy Elision anymore.