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.
The
std::leftandstd::rightI/O manipulators1) set the alignment of fields for I/O streams. To see the effect, you also have to set the field width usingstd::setw. For example:This outputs:
I/O manipulators are functions, and could be called with
(), but are usually called by the overloaded<<operator which takes these manipulators as function pointers:What actually happens in
std::cout << std::leftis:1) I/O manipulators are the functions in the
<iomanip>header.