Hi, welcome to the 21st tutorial in the c++ programming series, and in this part, we'll be looking at string streams. String streams allow you to use a string and treat it as a stream, basically allowing you to extract or insert to learn from strings in the same way as you can do on console and console. And this feature is mainly used for converting strings to numbers, or converting numbers to strings. For example, if I have a high school, let's say 1200, and it's a number an integer, but I want to display that to the screen to display to the screen, you need to use a string stream you'll convert the number to a string stream then you will display the string string or if you have some sort of On screen text, and it says 200. Perhaps you want to talk about this little notification path you want to manipulate.
And you need to use a string stream to put a string value into an integer or a float or some sort of number variable. Let's just show you a quick example of how to convert a string to an integer. It is really simple as a few lines of code. First of all, all you need to do is include two headers. One will be the string header. One will be destroying stream header which is F stream is going to get rid of this for a moment.
So we're going to do we need to do STD string belongs to the std namespace. I'm gonna call it str this variable. I'm gonna initialize it with the text for like Barris my six four byte is normal. A normal number in this instance, it's a piece of text is a string. So it tracks the distance Use it in an intuitive easy to use string string like sessemann just create a local variable called int i. And we're going to do STD string stream at string stream belongs to a standard Mac space open bracket and specify the string then we do the greater than greater than basically saying the string value was on the left, we'll go to the the variable on the right, okay.
And now we can just print this line we are sick for right. So for example, if I want to multiply that by 1316 but what would happen if we were to multiply str to fail because even though that look like a number, it's not it's a string, so you have to put it into a numbers you could use a float if you wanted to ask what you needed. And then you can do your mathematical operations on IT operations on it. That's it for this tutorial. In the next part when we look at conditional statements if you have any questions, feel free to message us at support at Sumner systems. Dakota, UK, the email will be in the description.
You can come to this video with direct messages via YouTube, whatever you feel comfortable with. All the recording for source code will also be in the description. And as usual, thanks for watching and I hope you have a nice day.