1
00:00:01,190 --> 00:00:10,070
OK, so we are now at the point in which we are going to go over and not only just putting data into

2
00:00:10,070 --> 00:00:16,220
our own programs, but getting data from the user to use in our programs.

3
00:00:17,030 --> 00:00:21,800
So up until this point, we have kind of been making these standalone programs that are almost just

4
00:00:21,800 --> 00:00:25,520
like a simulation rather than an interactive program, right?

5
00:00:26,210 --> 00:00:33,530
We've just been hard coding, like making our own data into the program, into the file that we write

6
00:00:33,530 --> 00:00:35,630
the code in and then we run it.

7
00:00:35,630 --> 00:00:38,450
And it just kind of does something and shows us something.

8
00:00:38,450 --> 00:00:40,900
But that's kind of a simulation.

9
00:00:40,910 --> 00:00:42,920
It doesn't allow us to interact with it.

10
00:00:43,490 --> 00:00:49,130
Modern software you notice on your computer like you can normally click things and whatever software

11
00:00:49,130 --> 00:00:53,880
you are using or you can type things, and we're going to get into that realm right now.

12
00:00:53,900 --> 00:00:58,250
Of course, we're going to start out with the easier thing, which is typing things and specifically

13
00:00:58,250 --> 00:01:01,280
typing things into the console.

14
00:01:01,520 --> 00:01:02,750
What do I mean by console?

15
00:01:02,750 --> 00:01:07,850
If you forgot what that was, it is similar to kind of what is in the terminal.

16
00:01:08,120 --> 00:01:09,080
We use the terminal.

17
00:01:09,080 --> 00:01:15,470
The terminal can kind of double as a console because when we run the program, we notice that our output

18
00:01:15,470 --> 00:01:19,400
like Hello World and stuff was going to be terminal there.

19
00:01:19,520 --> 00:01:20,990
So it's kind of seen as the console.

20
00:01:21,350 --> 00:01:25,880
Also, the console could be at the bottom of the screen or something in your I.D. or.

21
00:01:26,940 --> 00:01:31,710
You know, wherever it's just kind of a box where the output goes and it shows you the output, so wherever

22
00:01:31,710 --> 00:01:37,530
your hello world and other text that we've been using or mathematical operations that were printed using

23
00:01:37,530 --> 00:01:41,350
the sea out, wherever that showed up, that's kind of what the council is.

24
00:01:41,480 --> 00:01:42,750
I just wanted to point that out.

25
00:01:44,310 --> 00:01:47,700
So specifically today, we're going to be talking about the sea in object.

26
00:01:49,570 --> 00:01:51,100
So what is the see in object?

27
00:01:51,820 --> 00:01:59,260
Well, we've already seen the sea out object for output streams, so it's seen is very similar, but

28
00:01:59,260 --> 00:02:01,750
instead of an output stream, it's an input stream.

29
00:02:02,470 --> 00:02:08,530
So when we use sea in a C++ code, what it does is enable us to capture keyboard input.

30
00:02:08,530 --> 00:02:15,730
So the keystrokes that the user is typing after they run the program in the console, which the user

31
00:02:15,730 --> 00:02:19,270
in this case will be us because we'll be testing our own programs.

32
00:02:21,710 --> 00:02:25,400
So the keyboard input is saved to something called the keyboard buffer.

33
00:02:25,700 --> 00:02:32,240
So just imagine this buffer as a magic array where it just contains all this stuff that's been entered

34
00:02:32,240 --> 00:02:34,100
and it all happens behind the scenes.

35
00:02:34,130 --> 00:02:39,590
So I'm not going to get into too much granular detail about it because I think that it's kind of defeating

36
00:02:39,590 --> 00:02:43,040
the point of the reason that I'm introducing this right now.

37
00:02:44,780 --> 00:02:50,930
So rather than just using the stream insertion operator as we have with see out, that was the less

38
00:02:50,930 --> 00:02:54,380
than less than sign that came after the word sea out.

39
00:02:55,280 --> 00:02:56,990
We're going to flip that around.

40
00:02:56,990 --> 00:03:02,450
So it's going to look like this right here, and this is something called the stream extraction operator

41
00:03:02,450 --> 00:03:05,480
instead of insertion operators, the extraction operator.

42
00:03:06,200 --> 00:03:08,270
So when you use it, it looks something like this.

43
00:03:08,270 --> 00:03:10,460
We put the word see in rather than see out.

44
00:03:10,460 --> 00:03:16,340
And then we put these this flipped symbol here greater than greater than and then we read it into a

45
00:03:16,340 --> 00:03:16,910
variable.

46
00:03:19,850 --> 00:03:26,450
So here's a really basic example I make an integer variable that I declare, then I use scene to read

47
00:03:26,750 --> 00:03:29,650
the console input into this integer.

48
00:03:29,660 --> 00:03:35,750
So what's happening here is something that's kind of the exact opposite of what we did with see.

49
00:03:35,960 --> 00:03:43,130
So see out had is basically instead of seeing we had a out, then we had these flipped right, so the

50
00:03:43,130 --> 00:03:45,620
openings were facing to the right.

51
00:03:46,730 --> 00:03:52,310
Agree there was like the they were less than science, so the greater than part, the opening is we're

52
00:03:52,310 --> 00:03:54,050
facing this way toward the variable.

53
00:03:54,740 --> 00:04:00,260
And remember how I'd kind of described in a previous lecture that it's like our data from the variable

54
00:04:00,650 --> 00:04:07,610
was flowing through those openings into the console out, which is see out, sort it flowing out to

55
00:04:07,610 --> 00:04:10,180
the console for that console out.

56
00:04:10,190 --> 00:04:11,450
This is console in.

57
00:04:11,930 --> 00:04:13,970
So the data is coming from the other direction.

58
00:04:13,970 --> 00:04:20,270
The data is flowing from the console through these openings into the variable.

59
00:04:21,720 --> 00:04:22,890
So that's the difference now.

60
00:04:23,970 --> 00:04:28,380
So what happens is when you run the program in the console or terminal, wherever you want to think

61
00:04:28,380 --> 00:04:32,390
of that S and the C in line and your code is reached.

62
00:04:32,400 --> 00:04:38,580
So this is like at this point, it's machine code, but once the computer recognizes that scene line

63
00:04:38,580 --> 00:04:39,360
that you coded.

64
00:04:40,320 --> 00:04:45,510
The program is going to stall at that point, so it'll pause and say, OK, I'm going to wait for the

65
00:04:45,510 --> 00:04:52,650
user to type something now, so it'll stall, wait for the user to type something and really important

66
00:04:52,650 --> 00:04:53,350
point here.

67
00:04:53,910 --> 00:04:57,900
So it does not continue until you press enter.

68
00:04:59,500 --> 00:05:07,360
And it won't always automatically continue when you press enter, it kind of depends on what your program

69
00:05:07,360 --> 00:05:11,110
is expecting, like how much input your program is expecting.

70
00:05:11,110 --> 00:05:19,420
But if you type enough stuff to satisfy the requirement of input from the program and you press enter,

71
00:05:20,290 --> 00:05:24,640
then the program will have a chance to continue executing.

72
00:05:25,850 --> 00:05:32,420
If you have more seen stuff, then it might ask you to, it might prompt you stall again and have you

73
00:05:32,420 --> 00:05:39,440
enter more until you keep pressing enter and you have kind of fulfilled all that CNN requirement, then

74
00:05:39,440 --> 00:05:40,940
it will be able to finish the program.

75
00:05:42,490 --> 00:05:49,000
So seeing at that point will automatically attempt to convert whatever you typed as input into, in

76
00:05:49,000 --> 00:05:50,290
this case, an integer.

77
00:05:50,500 --> 00:05:54,190
But really, it has to do with whatever type the variable is.

78
00:05:54,520 --> 00:05:59,710
If this was a float, seeing would attempt to convert the input you typed into a float.

79
00:05:59,920 --> 00:06:02,560
Same thing with char, it would try and turn it into a char.

80
00:06:03,880 --> 00:06:10,630
Then what happens, of course, is that data gets stored into the mine and variable and really important

81
00:06:10,630 --> 00:06:18,040
thing about the typing, though the the type of the variable is what I mean, because if you enter something,

82
00:06:18,610 --> 00:06:21,370
if you press some keyboard keys and keystrokes.

83
00:06:22,460 --> 00:06:29,090
That are not the same, really, as the data type that was expected for the variable that can lead to

84
00:06:29,090 --> 00:06:32,710
some strange, strange behavior and stuff.

85
00:06:32,720 --> 00:06:35,900
So we'll see that later on in this lecture.

86
00:06:36,680 --> 00:06:38,180
So that's an important detail.

87
00:06:39,620 --> 00:06:44,090
So let's look at a full example, so slightly more comprehensive, it's an actual program.

88
00:06:44,990 --> 00:06:46,380
Let's go ahead and trace through this.

89
00:06:46,400 --> 00:06:51,920
It's a program that just calculates the area of a rectangle that the user provides the width and height

90
00:06:51,920 --> 00:06:52,220
for.

91
00:06:53,000 --> 00:06:55,190
So I'm going to go over every single line.

92
00:06:56,150 --> 00:07:00,680
It may seem redundant, but I'm doing this just because I think that it can't hurt.

93
00:07:01,130 --> 00:07:08,030
And if there might, maybe there's some people out there that are still a little confused on the flow

94
00:07:08,030 --> 00:07:11,210
of some of these introductory programs we've been writing.

95
00:07:11,220 --> 00:07:16,730
And so I would like to just go step by step since I haven't really had a chance to do that a lot.

96
00:07:16,730 --> 00:07:24,860
And hopefully that will help solidify things for the potential people that may not completely grasp

97
00:07:24,860 --> 00:07:27,200
how our current programs are working.

98
00:07:29,110 --> 00:07:35,830
So first line here is the include directive, and specifically it's including EO stream.

99
00:07:36,370 --> 00:07:42,340
This enables us not only to use the C out that we've been using, but also the C in that we are just

100
00:07:42,340 --> 00:07:43,270
learning about now.

101
00:07:43,270 --> 00:07:50,380
So seeing as part of our stream as well in this specific program, we are deciding to use the namespace.

102
00:07:50,410 --> 00:07:51,430
Of course you don't have to.

103
00:07:51,440 --> 00:07:57,220
You could put a Stevie Colon colon in front of the C out and would also need to put Stevie Colon colon

104
00:07:57,490 --> 00:08:01,510
in front of the C, and if you did not choose to use that standard namespace.

105
00:08:03,900 --> 00:08:06,240
Next, we define our main function, of course.

106
00:08:07,200 --> 00:08:12,180
Then we declare a width integer variable.

107
00:08:13,050 --> 00:08:15,150
So this will be used to store the width of the rectangle.

108
00:08:16,020 --> 00:08:16,710
Same thing.

109
00:08:16,980 --> 00:08:19,680
This is going to be used.

110
00:08:20,100 --> 00:08:21,290
It's called height, and it's not.

111
00:08:21,300 --> 00:08:22,110
This is a typo.

112
00:08:22,140 --> 00:08:25,070
It's not supposed to be used to store the width.

113
00:08:25,080 --> 00:08:27,030
It's going to be used to store the height.

114
00:08:28,900 --> 00:08:34,960
And then we print out a little message to the user to ask them to please enter the width.

115
00:08:36,150 --> 00:08:42,290
So this is printing out to the console, and it's going to prompt them to enter a value for it.

116
00:08:43,140 --> 00:08:52,070
Next, we actually read that stuff that they typed into the width variable using in on the next line.

117
00:08:52,080 --> 00:08:53,510
We do the same thing with the hype.

118
00:08:53,520 --> 00:08:58,620
We ask the user by showing a message printing to the console for them to enter the hype.

119
00:09:00,260 --> 00:09:08,330
Then once again, we you see end to read whatever they typed into the height variable now on this last

120
00:09:08,690 --> 00:09:14,750
informative, kind of useful line, we print out the area of the rectangle, so we have a little message

121
00:09:14,750 --> 00:09:17,780
here that says the area of the rectangle is.

122
00:09:17,780 --> 00:09:23,600
And then after that we see out another thing, which is the width times, the height we are using the

123
00:09:23,600 --> 00:09:27,020
multiplication operator, similar to how you've seen in previous lectures.

124
00:09:27,530 --> 00:09:33,620
And we're multiplying these two variables that hold the values that came from the user.

125
00:09:34,710 --> 00:09:38,460
The width from line eight and the height from line 10.

126
00:09:38,790 --> 00:09:45,180
Then we have an in line at the end here, the main function returns a successful exit code back to the

127
00:09:45,180 --> 00:09:47,160
operating system and our program is finished.

128
00:09:49,540 --> 00:09:54,190
So that's a pretty simple example, this consider another example, so the only difference in this one

129
00:09:54,190 --> 00:09:59,640
is that we have three variables and that we are not taking them in on separate lines.

130
00:09:59,650 --> 00:10:02,860
We are taking the input in all on the same line.

131
00:10:02,980 --> 00:10:06,100
And the same line is which we print out the message.

132
00:10:06,730 --> 00:10:11,380
So we print out a message that says enter label width height all at once.

133
00:10:12,530 --> 00:10:14,840
So it kind of prompts the user to enter them all at once.

134
00:10:15,650 --> 00:10:21,470
Then what we do is on that same line, we read it in with CNN, so we read in.

135
00:10:22,320 --> 00:10:28,100
Here's the extraction operator and we noticed that the extraction operators are separating in all three

136
00:10:28,100 --> 00:10:29,120
of our variables here.

137
00:10:29,120 --> 00:10:31,880
So we're reading in the label the width in the height.

138
00:10:31,890 --> 00:10:37,670
So this time our rectangle has not only a width and height, but also a label which is expected as the

139
00:10:37,670 --> 00:10:39,650
first input for the user to enter.

140
00:10:41,310 --> 00:10:42,990
Then we calculate it down here, of course.

141
00:10:44,600 --> 00:10:50,870
So this is us choosing to have the user enter everything on one line in the same line as which we prompted

142
00:10:50,870 --> 00:10:52,010
them with the see out.

143
00:10:53,970 --> 00:10:58,620
So let's take a look at what happens on the other side of things, so not in the text of our program,

144
00:10:58,980 --> 00:11:02,400
but what happens when we run our program and what the user sees.

145
00:11:03,750 --> 00:11:05,430
So here's a few examples.

146
00:11:06,450 --> 00:11:12,210
I go ahead and I've made an executable called input out an executable or a binary, depending on the

147
00:11:12,210 --> 00:11:12,870
system you're on.

148
00:11:12,870 --> 00:11:15,300
This is input out because I am using Bash.

149
00:11:17,060 --> 00:11:20,240
And you noticed that this one looks OK, right?

150
00:11:20,420 --> 00:11:24,950
I enter a label, I then a space, then within a space, then a height.

151
00:11:25,370 --> 00:11:30,400
Then it says the area of rectangle B, which is the label, is eighty eight times ten.

152
00:11:30,410 --> 00:11:31,370
That makes sense, right?

153
00:11:32,000 --> 00:11:36,020
However, these other ones don't make a ton of sense, so let's talk a bit about that.

154
00:11:36,380 --> 00:11:44,300
So most people would probably think that the a user would see this program and they would just be like,

155
00:11:44,300 --> 00:11:49,280
Oh, I'm going to enter things in the order that they have mentioned here label width, height.

156
00:11:50,030 --> 00:11:56,240
That would be a wrong assumption, though you should never assume that the user is going to follow your

157
00:11:56,240 --> 00:11:59,720
expectations or even your instructions, for that matter.

158
00:12:01,230 --> 00:12:09,120
You should always be on the defense, and most importantly, because hackers can actually intercept

159
00:12:09,120 --> 00:12:15,450
and input that can lead to you not only the crashing of your program based on that input, but also

160
00:12:15,900 --> 00:12:21,180
it could eventually lead to them having control over whatever system your program is running on.

161
00:12:22,230 --> 00:12:27,630
This is something outside the scope of this course, as it's more of a computer security topic.

162
00:12:28,170 --> 00:12:33,270
But yeah, it can be bad if you do not sanitize the user input.

163
00:12:33,270 --> 00:12:40,200
If you do not write code, that makes it makes your program not be so vulnerable to whatever the user

164
00:12:40,200 --> 00:12:40,710
enters.

165
00:12:41,130 --> 00:12:46,080
You should just assume that the user is going to enter any possible thing that could be entered.

166
00:12:46,080 --> 00:12:54,630
So you want to protect against malicious input that could lead to a compromised system or, you know,

167
00:12:54,630 --> 00:12:59,580
just crash your program kind of in less extreme cases.

168
00:13:01,410 --> 00:13:05,370
So what happens if they enter things in the wrong order?

169
00:13:05,400 --> 00:13:09,690
Well, we see right here is not entered in the right order.

170
00:13:09,700 --> 00:13:16,110
We have a integer before the label, which was supposed to be a character and then a character and then

171
00:13:16,110 --> 00:13:18,900
another integer, and we notice that it says the area of the rectangle.

172
00:13:18,900 --> 00:13:19,350
Eight.

173
00:13:20,750 --> 00:13:27,500
Rather than it being rectangle B, and then we see that our answer is zero, what seems strange, then

174
00:13:27,500 --> 00:13:32,540
we have this one here where we got some weird results when a float was used, so eight point seven was

175
00:13:32,540 --> 00:13:35,870
used and that caused the program to also have a result of zero.

176
00:13:36,770 --> 00:13:42,770
Then this one down here, we noticed that there's no spaces in between the user input and in fact,

177
00:13:42,770 --> 00:13:44,510
the program didn't even finish.

178
00:13:45,590 --> 00:13:52,640
And that is because it interpreted this in a certain way in which it thought that it still needs to

179
00:13:52,670 --> 00:13:53,720
collect input.

180
00:13:54,530 --> 00:13:57,340
So that is something we'll look into in the next slides as well.

181
00:13:57,350 --> 00:14:02,180
But here the program is hung up and it is still stalled, waiting for additional input.

182
00:14:04,420 --> 00:14:10,450
So let's specifically take a look at each one of these cases and not only see what's going on, but

183
00:14:10,450 --> 00:14:15,310
what is the keyboard buyer looking like, and then we will break down how the data is being read into

184
00:14:15,310 --> 00:14:17,560
the variables that we created in our program.

185
00:14:20,370 --> 00:14:22,200
So let's look at this top one first.

186
00:14:22,440 --> 00:14:28,620
So this is the one that was actually correct and had a expected result, at least I won't say correct

187
00:14:28,620 --> 00:14:35,820
because that's up to interpretation, whether we provided the correct instructions or not, but it came

188
00:14:35,820 --> 00:14:36,900
out as expected.

189
00:14:37,050 --> 00:14:42,750
The area was 80 and the label was B, so the keyboard buffer is right here.

190
00:14:42,750 --> 00:14:43,800
I have some boxes.

191
00:14:43,800 --> 00:14:48,420
Each one of these boxes kind of represents a character that is being stored on the keyboard buffer.

192
00:14:49,140 --> 00:14:54,480
Down here, I show kind of what we're expecting with each piece of the input.

193
00:14:55,320 --> 00:14:59,130
So first is a B, and that's OK.

194
00:14:59,160 --> 00:15:00,510
That's read in as a chart.

195
00:15:01,110 --> 00:15:07,020
The chart is just expecting one keystroke kind of because a car can just be one character.

196
00:15:07,030 --> 00:15:12,060
Of course, if you look back at the ASCII table, you can notice that most of the things that can be

197
00:15:12,060 --> 00:15:16,320
clicked on a keyboard and pressed on a keyboard are represented there.

198
00:15:18,200 --> 00:15:23,630
So that gets red and it moves on, it has a space separating the char and the next thing, which is

199
00:15:23,630 --> 00:15:24,200
a number.

200
00:15:24,980 --> 00:15:30,140
It reads in this character, but it's supposed to interpret it as an end.

201
00:15:30,800 --> 00:15:35,390
And it does because it's just an eight with a space after it.

202
00:15:35,840 --> 00:15:40,670
And so it reads in this eight and says, OK, an integer eight is being read in.

203
00:15:41,690 --> 00:15:46,200
Then there's a space and then there is a one on the buffer and a zero on the buffer.

204
00:15:46,220 --> 00:15:55,310
And since the integer doesn't discriminate against only having one, you know, against, sorry, I

205
00:15:55,310 --> 00:15:57,710
discriminate against having multiple digits.

206
00:15:58,160 --> 00:16:03,260
You know, an integer doesn't only have to have one digit like the eight, it could have, you know,

207
00:16:03,470 --> 00:16:04,310
tons of digits.

208
00:16:04,310 --> 00:16:09,500
So it sees this one and then it sees this zero and it's like, OK, that's an integer.

209
00:16:09,500 --> 00:16:10,550
And so it reads that in.

210
00:16:11,970 --> 00:16:16,290
And so everything works out, OK, because it was kind of entered in the expected order.

211
00:16:17,910 --> 00:16:19,220
Let's move on to this next one.

212
00:16:19,380 --> 00:16:20,460
So what happens here?

213
00:16:21,870 --> 00:16:28,890
So we have a be entered this kind of the same as the previous slide that begets readiness to cha OK.

214
00:16:29,400 --> 00:16:36,210
And then we have a space, then we have an eight and C++ actually reads this eight and there's an integer

215
00:16:36,210 --> 00:16:39,000
and it's like, OK, eight is an integer.

216
00:16:39,000 --> 00:16:40,110
I'm going to read that in.

217
00:16:40,110 --> 00:16:46,290
But the next thing was a dot, so I'm not going to have that be part of an integer.

218
00:16:48,060 --> 00:16:55,230
So what ends up happening with the rest of this is that scene actually fails on this because it cannot

219
00:16:55,230 --> 00:16:58,830
read the dot and the dot and as an integer.

220
00:16:59,370 --> 00:17:07,830
And so what happens is that it says basically the scene is an object, something that you don't need

221
00:17:07,830 --> 00:17:13,980
to worry too much about that terminology now, but it basically is able to note that it it failed.

222
00:17:13,980 --> 00:17:18,360
And so it sets some sort of status saying that, Hey, I failed.

223
00:17:19,080 --> 00:17:21,300
I failed to read this and something was wrong.

224
00:17:21,900 --> 00:17:28,680
And this is something that can be checked in a similar manner to how we checked for the what the length

225
00:17:28,680 --> 00:17:29,760
was of a string.

226
00:17:30,120 --> 00:17:35,280
Remember how we had like a string variable dot length and then it had parentheses, and I was saying

227
00:17:35,280 --> 00:17:39,330
that it was a length function that can be called on the string.

228
00:17:39,990 --> 00:17:45,510
Similarly, we can call a dot fail function on the scene object.

229
00:17:46,850 --> 00:17:51,710
And so don't get too carried away with the whole function being called an object.

230
00:17:51,740 --> 00:17:56,480
Yet I keep saying over and over again that we will get to this and you're probably pretty antsy for

231
00:17:56,480 --> 00:17:57,470
me to explain it.

232
00:17:58,310 --> 00:18:04,730
But right now, just think of this as being similar to the dot length, except it does something else

233
00:18:04,730 --> 00:18:05,210
for us.

234
00:18:06,110 --> 00:18:10,490
It tells us whether the input stream seen has failed.

235
00:18:10,490 --> 00:18:15,920
So whether encountered something that made it fail or not, this is something that we will be using

236
00:18:15,920 --> 00:18:20,990
in the next lecture where we write some code and we're able to check whether it failed or not.

237
00:18:22,190 --> 00:18:30,050
So at this point, what happens is that there's kind of all this stuff left from the keyboard, but

238
00:18:30,050 --> 00:18:33,280
it failed at this point, and so we're not really going to read it in.

239
00:18:33,290 --> 00:18:36,770
And what happens is that the result just turns out to be zero.

240
00:18:36,770 --> 00:18:42,920
Even though this integer got red in the second integer was not successfully read, and so we didn't

241
00:18:42,920 --> 00:18:44,300
get our expected result.

242
00:18:47,200 --> 00:18:48,470
Let's take a look at this one.

243
00:18:48,490 --> 00:18:53,950
So we have a similar thing, except the eight is the first thing.

244
00:18:54,310 --> 00:18:58,270
Eight is a totally valid character, totally valid char.

245
00:18:58,510 --> 00:19:03,550
You don't have to just have letters, pretty much any keyword press like we were talking about with

246
00:19:03,550 --> 00:19:04,570
the ASCII table.

247
00:19:04,570 --> 00:19:10,430
The AC III table can be considered as a legitimate char.

248
00:19:10,450 --> 00:19:13,000
And so the eight gets read in is a char.

249
00:19:13,000 --> 00:19:16,000
Rather than it being seen as a number, it's seen as a character.

250
00:19:17,080 --> 00:19:18,370
And so it's fine with that.

251
00:19:18,370 --> 00:19:20,550
So the input stream continues.

252
00:19:20,560 --> 00:19:28,300
It has the space, but then it encounters a b and it attempts to process this b by reading it into an

253
00:19:28,300 --> 00:19:30,370
integer process as an integer.

254
00:19:30,760 --> 00:19:32,200
Yet it struggles with that.

255
00:19:32,500 --> 00:19:34,690
And so it actually fails at this point in.

256
00:19:34,690 --> 00:19:43,510
This can be confirmed if you were to use a C and fail to to check it out and see if that was true or

257
00:19:43,510 --> 00:19:43,930
not.

258
00:19:43,930 --> 00:19:48,760
And you would notice that it is in fact true, it did fail if it tries to reel in a B as an integer

259
00:19:49,090 --> 00:19:51,070
and then we still have this leftover stuff.

260
00:19:52,970 --> 00:20:00,520
So the leftover stuff is something interesting that we will talk about in the future as well, probably

261
00:20:00,540 --> 00:20:06,920
the immediate future with either the next election or it's a, you know, immediately subsequent lecture

262
00:20:07,550 --> 00:20:11,510
because stuff can get left on this keyboard buffer.

263
00:20:12,350 --> 00:20:19,010
And then what happens is if you do not clear out the stuff left on this little magical keyboard buffer,

264
00:20:19,640 --> 00:20:24,230
if you try to go to scene something else again.

265
00:20:25,100 --> 00:20:35,750
It's instead of letting you type more stuff as the user is going to just grab whatever's already inside

266
00:20:35,750 --> 00:20:41,480
of this keyboard buffer so you can think of like, whatever the user types, it just stacks up into

267
00:20:41,480 --> 00:20:42,950
this keyboard buffer yet.

268
00:20:44,070 --> 00:20:48,960
If there's something that's already left there, like there's some leftovers, like you can think of

269
00:20:48,960 --> 00:20:55,470
some actual leftovers to be eaten, it'll eat up those leftovers first and read that into your variable.

270
00:20:55,470 --> 00:21:01,170
And that's kind of confusing because if you don't know that there's leftovers, then when you get your

271
00:21:01,170 --> 00:21:07,140
output, you're going to see some stuff that you didn't expect to be there because that's what you get

272
00:21:07,140 --> 00:21:11,430
read in other rather than like what you expect to be read in.

273
00:21:13,640 --> 00:21:16,250
So let's take a look at this last one, what happens here?

274
00:21:16,280 --> 00:21:22,460
Well, there's no spaces, so what happens is that the bigger threat in as a child, even though this

275
00:21:22,460 --> 00:21:26,600
is all smashed up against it, it's like, OK, a car is just one key press.

276
00:21:26,660 --> 00:21:27,350
This is a B.

277
00:21:27,350 --> 00:21:27,890
It's valid.

278
00:21:27,890 --> 00:21:29,690
I read that cars all get to go.

279
00:21:30,440 --> 00:21:35,750
But the second thing is these are the eight and the 10 smashed together.

280
00:21:35,750 --> 00:21:41,720
And honestly, you can't blame C++ too much for this because really, think about it if somebody wrote

281
00:21:42,170 --> 00:21:46,640
eight one zero right next to each other on a piece of paper and then they asked you to explain what

282
00:21:46,640 --> 00:21:47,270
that was.

283
00:21:47,990 --> 00:21:53,810
This can be interpreted in so many ways, but the most obvious thing is that it's the number 810, right?

284
00:21:54,620 --> 00:21:58,070
You're not just going to look at this and be like, Oh, it's for sure.

285
00:21:58,110 --> 00:22:06,290
Eight and then 10, it can be seen as eight, 10 as one number 810, it could be seen as eighty one

286
00:22:06,290 --> 00:22:06,920
and zero.

287
00:22:06,920 --> 00:22:08,930
It could be seen as eight and one and zero.

288
00:22:09,230 --> 00:22:10,850
It can be seen as eight and 10.

289
00:22:11,150 --> 00:22:11,960
All those things.

290
00:22:11,960 --> 00:22:17,360
So you can't really blame C++ for noticing this as one integer eight 10.

291
00:22:17,360 --> 00:22:18,320
And that's what it does.

292
00:22:18,320 --> 00:22:23,270
It actually looks at this buffer at each of these spots, and it considers this one integer.

293
00:22:23,870 --> 00:22:26,240
Well, why does it just stay blank here?

294
00:22:26,240 --> 00:22:29,390
And it does not show my bash prompt again.

295
00:22:29,810 --> 00:22:32,180
That's because the program hasn't finished.

296
00:22:32,180 --> 00:22:33,500
Well, why hasn't it finished?

297
00:22:34,250 --> 00:22:36,560
And that's because it's only read in one integer.

298
00:22:37,010 --> 00:22:43,730
Yeah, in your program, you specified for it to continue trying to read in a second integer after this.

299
00:22:44,390 --> 00:22:47,390
So it's still waiting for that next integer.

300
00:22:47,390 --> 00:22:49,970
And that's why you notice the program has not finished.

301
00:22:50,240 --> 00:22:56,990
You would have to, you know, continue to enter an integer and and or press the enter key.

302
00:22:57,170 --> 00:22:59,870
So that's why that looks like that.

303
00:23:01,740 --> 00:23:03,900
So enough of me explaining this stuff.

304
00:23:04,140 --> 00:23:09,900
Hopefully, though, it was some good graphics to help you understand how the scene really works.

305
00:23:10,380 --> 00:23:14,460
Hopefully, you're also pretty excited that we can make some interactive programs now and that is what

306
00:23:14,460 --> 00:23:20,310
we were going to do in the next video and some of the subsequent videos.

307
00:23:20,580 --> 00:23:26,820
We will be making some more interactive programs messing around with user input, but most importantly,

308
00:23:26,820 --> 00:23:28,260
in the immediate future.

309
00:23:28,260 --> 00:23:34,590
In the next video, we will be trying to see all the ways that you can really mess up with the input

310
00:23:34,950 --> 00:23:39,350
reading and is the wrong data type and stuff like that getting unexpected results.

311
00:23:39,360 --> 00:23:45,750
We're going to kind of suss all that out and throw it out there so you can really see what could potentially

312
00:23:45,750 --> 00:23:47,700
happen when reading and user input.

313
00:23:48,510 --> 00:23:53,070
OK, so with that, go ahead and open your next text editor if you're going to continue on from this

314
00:23:53,070 --> 00:23:53,760
exact point.

315
00:23:54,300 --> 00:23:59,040
Otherwise, if you take a quick break, I will see in the next lecture in whatever text editor you might

316
00:23:59,040 --> 00:24:02,130
like, I'm going to go ahead and use Visual Studio Studio code.

317
00:24:02,130 --> 00:24:04,080
I believe potentially.

318
00:24:04,560 --> 00:24:06,420
But with that, I'll see you in the next lecture.
