In this video, we'll learn about some of the c++ stream manipulators.
C++ streams have many useful member methods that can be used to
control formatting.
There are methods that work on input and output streams,
but formatting output is much more common.
An important concept to understand is that when we manipulate a stream for formatting,
sometimes the settings we make will be set for the remainder of the program,
other times they'll only affect the next object placed on the stream,
and sometimes their effect is immediate.
When we go over the individual formatting methods and manipulators,
I'll show you the effect each one has as well as how long the effect lasts.
Most of the stream formatters come in two versions,
a method version and a manipulator version.
The method version is simply a method call that you use with the stream object.
For example, cout.width 10.
I'll explain what this does in a later section. But for now, you can see the syntax.
It's calling the width method on the cout object.
There's also a manipulator version, which is designed
to be used inline as a stream insertion. In this case, set w10.
As you probably guessed, the manipulator versions are simply overloading the insertion operator
to make this easy to use.
To use the manipulators, you must include io manip.
The code we'll write will focus mainly on manipulator usage,
but I'll also show you how to use the methods.
In the next few videos, we'll go over some of the most commonly used stream manipulators.
Here's a preview.
We'll first start by looking at formatting Boolean types.
We've already seen this used in the course in a few places.
We can use bool alpha and no bool alpha to display Boolean values
as either the strings true or false or the integers 1 and 0.
Then we'll look at formatting integer types.
These manipulators allow us to display integers base 10, base 16 or base 8
as well as to decide whether we want the base prefix to show
and in uppercase or lowercase.
We can also decide if we want positive numbers to show the plus symbol in front of the number.
Then we'll switch over to floating point numbers.
Again, we've already seen some of these manipulators used in the course.
We can use fixed point, we can set the precision,
we can show the number in scientific notation format,
and again, we can decide whether we want trailing 0s printed,
and whether we want the plus symbol displayed.
Then we'll learn how to output numbers and strings in fields of fixed width.
And we can see how we can left or right justify them within that field.
We'll also be able to fill empty space within the field to a specific character.
Finally, there are several other formatters that can be very useful.
Endline, we've already seen and used.
Flush can be used when we want to be sure that we flush out any stream buffers,
but it doesn't add a new line like endline does.
The last few we really won't talk about much, but I'm including them here for your reference.
Skip white space, no skip white space and white space
are typically used with input streams when
when you have very specific use cases about dealing with white space.
Okay. So in the next video, we'll start with the Boolean formatters. I'll see you there.