In this lecture I want to go over some simple input so we can start making some more interesting programs.
An input will come up again and again but for now we're going to keep this very simple so we can just
we just have something easy for us to to work with for now.
So we've already seen how to output something to the console.
And we did this using C out.
And what is called the extraction operator.
So this is the three here these two arrows are the extraction operator and we can chain them together
like this
so your I-ness say hello everybody.
Right.
So this sea out has this extraction operator and the way I remember it is the text here.
Hello everybody.
And the Endal will sort of funnel into sea out so the arrows kind of show where the data is going in
the sense.
So if we have something called Sea Ouch you'd still stand to reason that we'd have something called
Sea in.
So if out is the output to the console in would be in from the console and if you think that you would
be right here.
In fact you're exactly right.
There is something called Sea in and let's try an example of how to get some input from the console.
So we have char char input and let's just say Please enter character
this.
The Endal
will say seen and noticed how this operator which is called the extraction operator is the opposite
of the sea out insertion operator see char input.
CH So again how I remember it is c in will put things into and there's little arrows into this.
In this case this char variable and the opposite for sea out say see Ouch.
Character
inputted is
share in
so let's see what happens if you're in this.
So please insert character and notice how it's waiting.
It doesn't just do this line 16 and line 17 and line 19.
It's actually waiting on line 17 right now for you to actually input something.
So as input he and you press enter and then it'll it'll actually stop blocking on inputs and go to the
next line.
So this is very important.
This is a very important concept that will matter a lot later on.
So I put in e and it outputted that I inputted.
So let's run that again just to make sure we're not it's not crazy.
Say a W and character you input is a W.
So just to show that it doesn't just work on char's Let's put like an integer here.
It's called input.
Put ch
in say Please enter a number number and the number you see number 10 and the number you inputted is
10.
So it works.
So cnt both see an NCO work on different types.
I can even have a float
in to see if input
this in again or favorite number one for and it's three point one for.
So just like the distraction operator for C Ouch which could Schene multiple things together a line
20 year we're chaining this tax rate here class the input plus the Endal and also chain multiple input
see either say if input to these Enter say two numbers and I'm going to say with space tween and I'm
going to change to the next one.
So if input to output here so you know say the first number you inputted and then out.
CH The second number put in.
If that's the word that's used for now.
Input to Andell.
Let's run that.
Going.
Always have the semi-colon.
Very important as compiler will complain to you.
So let's say three point one for in 6 3 9.
Sure.
And I notice there's a space in between you enter so and that puts exactly what we thought.
First one is Threepio and for the next one is six point eight.
The reason why we need to have the space in between is c in this extraction operator actually ignores
whitespace so a space would be a white space to be tambour the space bar or return line.
Something like this.
So let's run this again and say let's give it a bunch of space and then we'll enter three.
Another bunch of space and 23 and maybe more space after.
So still it just ignores the whole thing and then reads the float.
In this case.
And then again ignores all of the whitespace and then reads the next number 23 and outputs.
So just remember that the extraction operator is what ignores all the whitespace not see it.
So this is enough to get started for some simple programs that we're going to be working on in the next
few lectures.