Hi, i wanted to make a function which makes a spacing for a line every time I call cout.
but I am stuck.
my main goal is to use this line of code to work:
cout << lines(3);
which creates spaces 3 times
but my code so far is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int lines(unsignedshort l = 1)
{
l = (l < 1);
for (int i = 0; i < l; i++)
cout << endl;
return l;
}
ostream& operator <<(ostream& out, int (*f)(unsignedshort))
{
for (int i = 0; i < f; i++)
out << '\n';
return out;
}
The issue is you have an operator of the form "a << b". You need the implementation of this operator to know both 'a' and 'b', so that something like my_file_stream << lines(3) works just as well as std::cout << lines(3), otherwise there isn't a point to using the << operator.