I am learning C++ and my goal is to have a table beautifully displayed in console. I tried using std::left
and std::right
I/O manipulators, but now that I look at my code I cannot figure out what exactly these things are and what kind of mechanism they employ.
So far, every function call required me to at least put empty brackets ()
after the function name, so there could be no confusion for what is and isn't a function.
cplusplus.com and cppreference.com gave me an understanding that left
and right
are indeed functions, but those can be called without using brackets.
In short, why can I just put left
anywhere like this without brackets, but any other function call requires me to have brackets ()
?
Also, it says on cplusplus.com that left
is something called a "manipulator", but that's the first time I heard something like this. I have no idea what the term "manipulator" defines, nor whether anything on the website actually makes any sense.
operator<<()
supported by templated classstd::basic_ostream
(std::ostream
, and a bunch of other output stream types are specialisations ofstd::basic_ostream
). There are a heap of overloads, but three of them (numbers 18 to 20 at the link) are functions. Each of those overloads calls the functions passed to them, and are used to implement IO manipulators. One of those overloads will acceptleft
, call the passed function, which will perform required actions. – Bohn