C++ Programming Tutorial 7 - Using Variables with cout

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's going on everybody this video we're gonna be talking about how we can output variables in a pretty way and do string concatenation so right now we have this variable we output it it gives us the value five and then it just continues right on without putting a newline or anything like that so this is gonna be some pretty basic stuff but it's vital for making beautiful applications obviously this is just the basics but if you really get into C++ programming and you want to make sure that your applications are beautiful then I would recommend our sponsor Embarcadero C++ builder what is this you might ask well it's an IDE that allows you to build C++ applications and ultimately deploy to Windows Mac iOS and Android with that though is the responsibility of building user interfaces for all of these different screen sizes and platforms C++ builder makes this easy for you with drag-and-drop components that makes building user interfaces a piece of cake so if your goal is to deploy to multiple different operating systems with responsive designs that work on all these different platforms check out C++ builder I'll leave a link for you guys in the description all right so the easiest way to make more complex strings is to use this operator more than once so we can put another one after our variable and we can put anything we want so for example we could put an L and L is an example of a manipulator there are tons of other manipulators we're gonna be talking about some in this series but for now and L is important because it's just going to go down to the newline alternatively you can put a backslash n which will also go down to the newline but I'm gonna go with end L in this situation we got an error and that's because we are using this using standard C out we're not putting using standard and L so if you want to put another using up there you can but I'm just gonna preface this one just like that and now when we run it we get 5 on its own line we don't have to just print the variable though we can make a string around it so for example we could say you have and then it's going to list the number of slices and then what we can say is slices of pizza make sure you put spaces because there's not going to be automatically a space after the variable so we need a space before the variable and a space after the we don't need a space there though now let's run this when we do we get you have five slices of pizza awesome so what we did is we basically templatized this output meaning we have this original string you have blank slices of pizza and then we substitute a variable slices which we get from this value up here right so we can assign any value here and that's going to be outputted that shows the benefit of variables in programs you have ten slices of pizza this is just one simple example it would be just as easy to copy the value ten and put ten right here you might think the variable just adds another layer of complexity but as we go on we're going to be using variables more than once and we would only have to change it in one location to change everywhere that uses that variable which is why variables are super important so I'm gonna put slices back in there just like that now if you're coming from a C background or if you're just working with other C++ code you might run into a print F and what the heck is this printf is a function that comes from C but also works inside a c++ most stuff from c is going to work inside a c++ so we could do the same thing we could print slices and we actually need to say what output format it is so we can give it a format string and say this is an integer and then we could put a new line after it so when we run this we get ten and it works so this might look funny to you if you've never seen a printf statement and I would have to agree this is kind of silly see out is much better in that it can interpret the variable you don't have to worry about saying what type it is like in this situation I had to say it was an integer C out just knows that this is an integer so we want to output the value one zero so thank you C++ for making our lives easier we don't have to worry about that printf garbage anymore awesome so we are using this operator here to print slices and it works but later on when we make more complex data types if we put a variable here that's like a custom object it might not work right away and because of that we can to overloading and basically teach see out how to print a particular object very cool concept don't worry about it for now just know that this whole concept is very extendable and we're gonna get into some pretty cool stuff so thank you guys for watching in the next video we're gonna be talking about how to get input so we've done output with C out now let's talk about input thanks guys I'll see you in the next video [Music]
Info
Channel: Caleb Curry
Views: 39,332
Rating: 4.950562 out of 5
Keywords: C++, programming, tutorial, using, variables, with, cout, caleb, curry, calebthevideomaker2, code, coding, c++ tutorials, c++ for beginners
Id: CEZhVC_rd1g
Channel Id: undefined
Length: 5min 10sec (310 seconds)
Published: Sat Jan 19 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.