C++ working with files using fstream library | Arkadiusz Włodarczyk | Skillshare

C++ working with files using fstream library

Arkadiusz Włodarczyk, Professional teacher

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
16 Lessons (2h 45m)
    • 1. Introduction

      3:26
    • 2. Streams - what is input and output

      6:27
    • 3. How to open and close files

      6:27
    • 4. File opening modes

      13:24
    • 5. Stream's error flags

      17:41
    • 6. Reading position pointer - seekg and tellg

      8:53
    • 7. Writing position pointer - seekp and tellp

      3:55
    • 8. Extracting characters from files

      15:26
    • 9. Comparing content of two files

      25:11
    • 10. Put - loading characters from cin stream directly to file

      4:17
    • 11. Peek - peeking characters without extracting

      3:42
    • 12. Putback - returning extracted character on stream

      2:38
    • 13. Write - writing bytes to file

      5:42
    • 14. Gcount - counting characters from last operation

      3:35
    • 15. Mini database

      42:03
    • 16. What after this course

      1:57

About This Class

This course is about operating on files in C++ language usingthe fstream (file stream) library.

This course consists of over 2 hours of great content. Before buying, please watch free videos so that you will see for yourself if you like the way I teach.

You do not need to know anything about operating on files,but it's good idea to know the basics of C++ language.

After this course you will know:

  1. how to operate on input and output streams,
  2. how to open and close files and how to handle errors connected to that operations,
  3. states of file opening,
  4. stream’s error flags,
  5. how to check the size of an opened file,
  6. what binary files are and how to compare them,
  7. how to extract and save the content of a file,
  8. how to create a mini database that allows you to add, show, search, remove, load, and save,
  9. many functions about working on files

If you have any questions regarding the topics covered in this course after watching the videos please feel free to ask. I'm always happy to help.

Transcripts

1. Introduction: Hello, everybody. Welcome In the video call C++ about operating confides you learned in the Cows Fi Stream library where my my name is our catalogue logic, and I'm water off over 25 video curses in Poland. I love teaching other people. I'm also alter off the calls c++ from bagging them toe expert level. That course is the first cause. You should watch these. The second course about the library that is used to operate on five. What? What do you need to know about the C plus plus before you stop the adventure with that course? So we will not Lucy or precious time. Let's stop from that. You will have to know the c++ basics. So you will need to know water for Ebel's pointers function structures, loops and automatic bid was relational logical operators. If you know that, you will be OK to stop that course. Okay, Now would you is no after the cause because it's really important. Well, you wouldn't know how to operate input and output streams. He would note what are what these input and output you. We also know that after the free lessons, so check it out. You know how to open and close fights and how to handle arrows connected to the operations . Well, no state of fire burning. So you know how to open the fire so we can upend character to it. Or you want to open the file to remove the content at the start of opinion or something that you will. No three means arrow flags. You will know how to check size of opened fire. You know what are benign, rethought fights and how to compare them. You will know how toe extracts and safe content on the fire off the fire. It is very important topic you and also create Amy database that allows you to at show, said she move load safe people. So it's pretty cool. It is the last lesson, and you will also let Manny functions that supports working with five. You can check out the description, and you will know exactly what you will learn after the car. Call the course if you want more specific description of the cars. Okay, so what will we use? We'll use the cold blocks. Integrated development environment. It doesn't matter what you will use because you can use the coal blocks, you can use the visual C plus. Plus, you can use the deaf C plus. Plus, it doesn't matter. It's just an editor. Don't worry. If you want to use the same editor, you can just type that editor into the browser. It is for free, so you can just download it on. Everything will work. Fine. Okay, there is one more. Fink. Make sure that you check free lessons. So you will know if you like the way I teach. Okay. And if you have any questions, feel free to ask them. I'm going to answer them for sure. So don't worry. I'm happy to help. So have fun and good luck. Thank you very much. 2. Streams - what is input and output: Hello, everybody. Today we're going to talk about streams. About the input about output. We would like to be more firm. Millar with Ted reports. Otherwise, we have just problems. Will have to memorize everything by heart. So we won't understand. It will just write some kind of coded won't understand. Let's understand the stopping from the scotch from the begging. Okay, So what is the same? Well, let's look at the pictures. Look, here is the stream, But what? They'll held its stream. You see Europe above the right now a disease just Walter, let's talk about programming, right? Of course. We talk about programming, but look, he was the stream. You can see the the water is moving. There it is flowing from one place to another from something Go. This called input to something with these output. Look, from the top to bottom stream. Is there some kind of object in programming that allows us doing these operations behind the scene? Right. And they could stream just because of it, because they're allowing us to do this things right. Okay. And now Okay. So what is in the programming, for example, input. What is the water in the program. Well, look at the programming and situation in the programming language. The water is information, but right by that they're moving from one place from something. Body sculpt and put to another price. So, for example, variable Or, for example, something good is called output. For example, toe the monitors. We can sit right. Ah, So to sum up we can move, for example, bites represented by characters from the user keyboard, which is in put in that situation to the file. We just output in that situation so we can think about input. Ah, as an entrance to something right. It is a source late for we can put something in, for example, characters. They are waiting there, and we can extract them. So the input is like the source. We can extract things from the embassy and we can think about output as the place where you want to put something out. Look, how emphasized that Think output put out something right? We can also example hearing the Coleman the synthetic, put in from a ski boat, put art to the fire. So, as you can see in boot out food, right, so out to be some kind of destination and put input is some kind of source and fronts exit something. Here we have a very simple program which right now that's nothing. But, well, we called here for a large library with this input output stream. So it has got an object stream which allows us flowing, moving the information from input to output. Right now, the input is represented by the object weeks. We just called c in. So it is like you can, for example, remember it is CPP in Booth, we can put things there, do that thing and you can take things from that input. Exactly. We can boot their characters from the key boat and we can put them later. For example, Tova Rabel A which we have to also declare here defining and when around this program. And right now I am typing numbers and the numbers are being popped put here and then they are moved to a so on the input. Things are waiting and when we type here and then they are moved to the very book. But we can also move that things toe other place. We could also move them to the outward right so we could do something, for example, See out. Let's send something to the output. So with that arrow and something like that, we are moving it outside so everybody can see so we can run it. And as you can see now we can see also that 55 that we put here. That the import and look right now we are not talking about five. Somebody say no. Look, it is very, very similar because right now we can, for example, take things from this source from, for example, input and put them inside the fight. Or we can say that the file will be the input. It will be the source this time and we'll take things from there. And we'll put it outside toe, for example, User, so he can see it on the mind. So you see, the fight can be wants the source and once it can be the destination, I want to sometimes, right? Do it. But you can. I also want to We can also take things from the fire, right? It also it all depends on the situation and we will talk about the situations. We also talk about other library that we exactly do thinks five it is very similar in next lesson. Thank you very much. 3. How to open and close files: Hello, everybody. Today we're going to talk how to open close and right to fire. But remember, we'll do it the simple way So we would just know how to opening, how to write to it and how to close. Well, no talk about the advanced topics. Like, for example, a pending to the fire opinion. Is that the Binali fire and other things like that? We just want to simplify that so we can learn it step by step. Okay, so we want to learn about the library. We discovered five stream so extreme stands for five string. So it is operating on five. And it is really, really similar to the art input output stream. This time we will treat the file as an input or as an output. Well, we'll decide how we want toe treat that fire. Firstly, we need toe create an object object that will, ah have inside the fire that we want to treat. That won't operate him. So let's create the object. So we will talk extreme and my five handle. So this is the place where we will save where we will, um, help our fine. And because we are you think you hear the extreme class. These objects has got lots off methods with functions that we can use here right now. And we can operate on that fire that will be opened here. Right? So let's open it. My fight hander and as you can guess, varies a method that can open the fire. He we can type the name off. I So, for example, test and the extinct. And right now we should be able to open the fight, test the test fire. And there is a problem because heroes you can see there is no fire lighted. And because of it, we won't be able to open it because it's not here. Right, So we should create it on here way are doing it. It's grated right now so that here is a pole Iverson inversion off this windows. But well, you know how to create the five for sure. So we're creating the fine. Okay, So it's not that we are open, you get the fighting is already created, and now we can do some things with it. Well, look, that fire right now that it's happened here, um is really at the output, right? It is the destination off the things that we can put the right or we can, for example, get something from inside example. We could get some things here, and we will drive toe, retrieve it, Extracted right now in this. Listen, let's just put something inside there, so let's make it as an out look when you have something like see out. So the character output were moving something there. Right? And here it is no different. Right now we're moving something. Toe the my five handler and, for example, this ISS saying a simple text. Right. So we're moving it here. We could also do something like that that's here. It is really very similar thing. Okay, so we're moving these desks here and now we should also calls the fight. Why should we close the fire? Well, you know, firstly, you could use the my 500 toe open. Other fights. Secondly, now we are for making, um our resources, more resources and other things like that. Free. We are not operating on the fire and more so we are making it free. We can work on other things like that. So it is good for her program for the health of our program for health of our competent that things like that eso we're freeing here our memory and we are allowing us to use them , my friend 100 more than once, right? So we're closing the fire, and right now we can compile it and run. And as you can see, when they opened if I Here we have this. This is this is some sample text, right? So we just We've just written that think in fact. So it works perfectly. We can also, for example, check it. If I has been open, probably some present my 500 And here is a function is open. So if then you can don't this insight and you can close the fight. Otherwise don't do it right? Said something like that, Andi, as we can see, for example, when we do something like that on the fight has bean open for a poor really that now it's not working. But when we use the name, find that that we create it. As you can see, the fight has been open properly on Of course, it's working fine. We can also notice that we can Could something God is simple text, for example. So we're at a here which was missing. And when I run it, you can see that it this added. But look, we are creating the fight from the beginning because you can see we're not adding on and to make things like that to add new text, not removing everything. We need to open the fire in some kind of mode and we'll talk about this bolts. In other lesson, we also talk upto extracting from that right now in business. And as you can see, we treated how where if I as what as, uh, output, right as the place where we can put thinks inside. Okay, thank you very much. 4. File opening modes: Hello, everybody. Today we're going to talk about the ways we can open the files because you see we can open the fights on and make them being on the read able on the right table. Or maybe we want to upend something at the end of the fire or maybe want toe open. And if I as a binary file so we can add it, for example, an image. So let's let about the flocks. Flaks are most for opening the file, so we can said, if I toe only be able to, oh, fright to them to read from them and other things like that, As I said, area. So let's get the comments so later you can read it easier. Um, as you can see would have got here. It called from the last lesson we have got only created a five which is tied this F stream and you are paying here a fire with the sample text Fi and we're checking. Give the fights open. If not, we are sending a proper message. And if not, if it is open, and then we will do something, keep right. So when we around, this program is you can see we have got here a matter. The fire hasn't been preparing opened, so Ah, as you can see, it is not cool that I would tow every time created five that way. Right. Using the windows of something that, um, we have to make sure that if I can be easy, is a curated through the C plus plus language, right? So how to do it? Why it's not being created in this place. It's because that file right now here has got some kind off flocks. Right now it is in some kind of moat and f stream default mode. Let's let's some 95 vote flacks. Ah, is input output stream input. And it has got also the flag, which is out. So it has got the to flacks like that. And let's talk about the flax here. So these guy IHS from input I in stands for input and it allows us to read from the file. So it is for reading, all right, reading from the fire and here we have good out and it allows us toe right to find. And when we have Teoh that two months up in the center in the same time when he opened the fire. We can write to it and read from If we had on Lee this think then we would allow only for writing to fight. And it is pretty easy to understand that when we have Onley, that flag on the five will create automatic Ari. Why is it so? Because look, when we can when we love somebody to write to something then, um we need a five which he exists, right? We can't have who can write to the to nowhere. So when you have the output Ah, flock, we can write it. If there is no five, then create it. And also, if there is a fire, then tragic aid it so remove remove for every remove content on Lis It's a course with IOS in flak. So when we have a default mold the right like now because it has also these flak we are not creating the file automatic car But if he was only this flag and we can change this behavior by simply using the second parameter here. As you can see, the default mode is set here that it is in and out and this could see we can study to only out no and when we comply it it's a conceit would have no error. And as you can see here, we have new fire. What is a sample text? So it's working very nicely. Ah, we can create a fire. But if we used as I said area, something like that is so the default mold on that's changed. For example, this name here. As you can see, the fight hasn't been open properly because it's not here. Of course, if we have the five there already, it is working pretty good. Okay, so we can change it here. We can also open defy by using the constructor here so we could say do something like that . It's good idea to know that it's possible to do also that way that you can see it's working Fine, but we'll use these syntax. Okay, so here we have the import. So it is for reading on them. There are more flags like let's see them throwing Kate, which he's from truncating and it is truncating the fight, cutting everything inside right Onda, we have got also something like eight, which sends for at D and and it is setting pointer at the end off five. So when they open fire, we've, for example, something like that. We have got the ah, the pointer at the end of fight and we were right at the end of fight. But the problem is that this flag is also truncating the fire. So we wanted to add something at the end. We would need to also ah, at that flock here, the input output stream in flak. Okay, so maybe let's check how it works out. And let's add to the fight, for example, Um simple, simple text. And for example, let's at another text him, that's at the end. The enter line. Now when we open the fires, you can see we have got here a sample text two times, and when you run the other game, we can notice that it's the same. Why? Because that output flak is cutting everything from inside. So when we met input Apple Stream in Epsom, then when we're on it, as you can see this ad Inc this think at the end. But we also need to remember that the pointer is at the end of the fight not only for righting here. It is also for reading. Here. We can read, write to this place. We can change the point where things are being put, so it is really important to know it. So Pointer can be changed. Maybe the place of pointer can be changed in that moment. It it's possible to read and write in that moat. It is very important. Why is it important? Because you have got also something like a pound mold the flock and the content is added at the end off fire, always at the end of five. And it is not possible to remove content nor adding something in other place than the end. Well, fine. So you see, the difference between these two months is that in the happened, we we have way have on the possibility two at things at the end. It's not possible to change afterwards. On to, for example, it's something the middle off off the open fire. It might be important in some situations when we try to do something so but it is also very , very important to notice that we will not need Teoh at that. I always in flux this time with the output Flak. Why? Because, as you can see, it is not possible to remove content them. So when you have got this toes together, when you're on it, as you can see, um, the sample texts has been added at the end and we didn't remove the counter, right? So it's pretty cool, too, because we don't need to add that flack him with it on. There is one more mold, which is binary, and it opens the fight as a buying narrow. Fine. Okay, so let's I think a second about what is binary file. And finally, fine is fine, he said. It is. It is just a typical fight every fiza binal If I So why did they even create something like text by byline? If I and other things like that? Because you see here in that program it is a note, but it is automatically changing that Binali form to the text form. So every 0111 is changed to, for example, as a MP, I called angry, right, so the text file is a binary ified. But when we use a note but we can interpret, isn't US attacks And here we have got a binary moat and not a Binah. Ramon, Another bine animals is a text mode. And the difference between the stows is on Lee that in the text mode, the default mode Ah, there is an enter adit, which is a bit would just always they gonna be interpreted the same way. Under any operation system, we use the binary. We might have problems if we, for example, change from the windows. Some kind of lean nox or other are other place we will change between binary and the text mode frequently or something like that. No, I have a problem with the enters. Right. And that's on the difference between here right now. So maybe you will need in the future. Maybe not. Maybe you don't need to even ah, be confused, writer. But you need to remember that if you want to open an image off some kind of archive like a zip, you would need to use the beina remote. So here is the very important difference than right. A Z can see a few. We have the F stream library. We have also the I F string library, which has the default mode input and 00 F Stream Library. Which default is out? The extreme has got inside because it in carats from if stream and off saying so, It has got all things from the stools guy. So maybe it is the best idea just to use it all the time, this thing. But you know, if you especially want to say that you want to just great just this thing don't especial say that they want to just put something inside the file, use the offspring. That's the way you shoot used that. The library's okay, that's all the lesson. Thank you very much. 5. Stream's error flags: Hello, everybody. Today we're going to talk about the streams Arrow flats Because, you know, sometimes when they open defies their my happen some kind of arrows you see, for example, might try to by mistake, a sign ever able. Which type is string toe the variable, which is in Teacher. We can try to retrieve something from fight. And by mistake, we we could do something that right, And then there will be some kind off earlier. And you can react on the errors because when some kind off off errors happen every time there is a state which we can read and we can react to it. So there are functions. Functions which returns through or falls depends depending on the situation. For example, we have got to function, which is called BET and, as you can guess, hisses, bad, bad situation. And these function returns to if there is an error like, for example, writing to fight, which was opened on Lee for reading. So it had the flock IOS a boat. We have to remember that this function returns the true because there exists a flag, a state we just called bad. But okay, so let's check it out on the practical example. As you can see, we're opening here a sample text which you would have got here and here. We have a simple text inside off. Okay, so let's open that fight right now on Lee for reading. And let's try to answer something inside. So for example Ah, sample texts about some singles. So we're trying to insert thesis sentence inside, but we cannot do it, right? So what happens when around it? As you can see, nothing happens. But when they opened, if I also nothing happens So what happens? You see? No. Right now we have got the state bad bit and we can read that state. For example. We can do it that way. Five bet, and we can send it to death output. And as you can see, we have got to you one. If we don't answer than the thing inside, then as you can see, we have got to your zero. OK, but well, why do we need something? I did look, when something like that happen, what would happen if I try to, for example, write something to the temporary five from the fire? So it's like that. Um, Violet sanded up. As you can see, nothing happens. Why? Because right now we have a big old bet. Um, bend it estate which say's we cannot do anymore anything on the fire. So, you know, right now, if you wanted to do anything on the fight, we would have to rest it. We have to clear the state. So we will need toe use the function which is called clear on it's clear the state. So we will need to use heres something like five. Clear and yes, right now when we were on this program, As you can see, we have got here a sample. So we have to clear we if something bad happens so we can check if I but 10 we can say that something happened and we can clear the state than do something as for example. Ah, OK, So what else flax do we have? We have got a function. We just called fail. And it is indicated by the favorite and the function fake returns through if we try to assign string toe in teacher while wide reading from five. So the the very boots are not the same type or when bad beats situation happens. So the Fae bit includes bad beats. But it is also indicating situation when we try to science string to intern, teacher Another wrong type, right? So let's check it out right now. We also learned how to take something from the fine. So we can, For example, let's create here a string which will call the buffer. So is buffering is some kind of temporary place where you can store the things and here right now we are directing things from the fire. Do the buffer and as you can see now we can send it to the output. Let's do it. As you can see, we have example here. But what happens when we have got here? And teacher, As you can see, we have got here zero because the stocks are wrong on. We have got their some kind off, um, casting, which is hidden from us. That's why we have got a zero. But you know, right now we have got a five. It we can also we can check it So as you can see again something like see out ah, five fail and line And as you can see we have got to you one which indicates that something faith So we can check if five failed, then say that it failed and we can rest it. Them, uh, the car on state. Right. Okay. We have got also a good fleck which indicates that everything is good. So it returns through. If everything, it's fine him Well, if any of the both flaks are false, right? So when we do something like, see out far good, we should enter here. So exactly that what is coming From what Ondas You can see we have got here zero so not everything is good But when we change it back to the string As you can see, everything is fine. Okay, Now let's imagine situation. I would like to read everything from the fight, but we have got here lots of more texts, right? Something like that on Want to read all text at once how to do it? It would be stupid. E we did it for example. Like that fight the buffer c out buffer And again and again. Of course, the thing would work But it is not a good idea to repeat things when we can use what loops . So we have to use the look. But when will the loop end? When we reach the end of the file. And that is the most important fact. Flock here with this end off fire E O f. Which sends for end five. And it is e o f bit. And it returns to, um if the file opened to read, reaches the end, both five. Okay, so let's try to use it. So we'll try to do something. So try to read something all the time and let's send it to the output. Why and why? We will not reach the end off five. So something that fired dot and the fight and when it on it. As you can see, we have got here all texts and at the end, we have got zero. Why is that zero here? That's the question. Good question, because you might think, Hey, everything is fine. We where? I didn't think so. We shouldn't worry about it anymore, but as you can see, I said, it threatens through if everything is fine. If any of the above flags are false, the problem is that and the five is true after reading everything from the fire and we have got no situation where we can do in the more anything with the fire. What if I wanted to do something now with the file, I will need to reset the state. But firstly, I would need to check if the state were just here. Waas end of file. Or maybe it was bad. Better, maybe five. Or maybe it was some off end of bidden fibers, right? Because these things can sum up also how it happens because you see the good bit. Zero. The end of it is for the favorite IHS. Um so the favorite is for the end of fight is still and the bad bit is one. And let's see how it is represented by bites. One is represented by 001 to the zoo, presented bar 010 and for is represented by 1000 Because we have got one in different places, we can some the these things together, and we can say exactly which one is happening at once together, for example, because of what? Because offbeat wise operators, for example, the contruction, the some and exclusive or operator. These operators are very well. Ah, Talk about in the first c++ language course we're just use it, Hugh, in the very practical place. Because you seem right now, for example, I'd like to check if that state here was really end of fire. I could check off course Eve the firewalls. And if I and ive bad fight, then if five. But how to give the stuff where at once, That I wouldn't to make lots off conditions. So it will be then long how to do it once and very well. Well, we can go. For example, something like that. We can use the read state function greet state, which is reading the site. Ah, that r and D is from breathe. It stands from re it right so we can wait the state, for example. Let's check it out. What happens when we do something like that right now? So five read state As you can see, we have got here too. So it means that right now we have got the end of fiber dio If you had the Fabi well care for If we had faded and end of Bill, we would have six. Okay, so when situation off something off, the beats happen Well, for example, now where did here and enter and that enter end of lying cannot be added to the string when you're on it. As you can see, we have got six here. So we have got in the same time favorite and under five. So something wrong happened. And because something wrong happened, we wouldn't like to continue our program the same way. Like if only we read the five properly on and we have to only red reset, the state went and the five big status on we can use the exclusive or here. Why? Because when you have got to Sikhs, for example, 110 and we do the exclusive are here. So, for example, on 010 the result off that think would be 100 So it will be four, which means that there happened more than just end of bit. If you cut situation like 010010 then we've had 000 from the exclusive or because exclusive war or works like that, that it is only true when only one off the bit is true and we can use it here, for example, like that if five read state, soar exclusive or we've And here we can use the i f stream and used the flags, which I talked about so badly. Favorite end of bid right now on that think end of bit indicates to So if something like that happens, um and it equals zero, then it means that it is for sure, and on and off bit on the end of it and we can reset the state. So we can, for example, say something The fire has been reading proper. Read properly, Andi. Now we can create the state easy. And as you can see now, we around this program we have got six year. Why? Because the state wasn't cleared. Why it wasn't clear because when, for example, we do something like that. As you can see, we have got here now for why is it for because, as I said here, it's for here, right? Six and two is giving us for But when we have good really a situation which is just end of five, we about the fate bit ah, well arrested the state and we can use again. This five toe do something goes okay? Of course. When we just cleared the state, it doesn't mean that we can read that fight again without in the problem, because there is some kind of indicator at all, which is indicating that it isn't the end of the at the moment we have to change these things. We have to move it to the beginning of the fight or something like that. But we'll talk about things like that later. So here you can just clear said indicator off place in fight some other place, Uh, and some other operations on fire. Otherwise, we could check if it was, for example, just Fabi. And he could just to a condition here and everything would be fine. Okay, There's only this lesson. Thank you very much. 6. Reading position pointer - seekg and tellg: Hello, everybody. In thes lesson, we will talk about the reading position pointer about the indicator off the place inside the fire. Look in the last lesson, we created a program where we retrieved all possible information from the fire. And when we did it, we cleared the state and that I know, unlikely. We just cleaned the state and we didn't do anything with their reading position point. Because of that, when we do something like and we try to send it, it output will not is that we have got to times important work here because it is the last world and it's because the pointer is right now at the end off the fire and we have to change that. The pointer and this pointer is called reading pointer and we have got to functions that we can use on the reading pointer and these functions are inside the F Stream library or inside input esteem library. It is not possible to use it inside out would have seemed library because it's easy to remember. It is just for reading like the input have seemed. Library FC Library has got both library so we can use it there and these functions, Kim tell. Where is the reading Porter off, said the reading pointer at the specific fight position. So let's start from getting the pointer. Let's see where it is right now so we can do something like see out and five and used the function tell get. And when you were on the program, we can see that the position of the pointer is 40 free. This position is and is the binder is the binary ah position. It means that it is 43 bites far away from the bagging of the fire. We should use the IOS binary flock here because sometimes the text mold, which is set by default, might have sometimes problem. We've interpreting free things, right? So it is more safe to use the Beinart here. Okay, so we know now how toe tell where is the reading pointer? And now let's learn how to set the pointer Summer. And maybe, let's ask ourselves, why would we even need something like that? Well, for example, you would like to read from the middle of the fire. Or maybe you would like toe back in the middle of the fight to the beginning. Or maybe you would like Toa. Just see how big is the fine? Oh, let's do something like that. Let's check. How big is the fire? So right now when we opened the fire in that line we are at the beginning of the Faisal. The ah tell get functions should return zero and how to get to the end of the fire. Look that see, get function has got a second overload function which you can use here. We can put the how many bites from the flag place we want to move our pro pointer and flag can take the begging And in current options, the begging is set by default. When we do something like far seek, get And when we put here, for example 40 it means that we are setting the point It at 40 bite from the begging So it means that we are doing something like that. But well, we want to set it at the end. So it might be hard be when we don't know how many characters are inside. We could read all characters, but it will be a big too long, but because takes time on the fight is very big, but we have got here flag would you can use. So let's use it. We have got the and flak and how many characters we want to move from the end and flak from the end of the fight. What come when they bite? When we type minus five, we'll move five five bites to the left when we type in five with the move five bites to derive. So when he type zero, we will be at the end of the fire. We are just not moving from the end of the fire. We're setting it at the end of the fire and because of it Now, when we use there five the get function here. Ah, we have got here inside the size of the fire. This size we can save to the stream position. Type off variable so size off. Fine, because tell, get function returns variable which tied the stream position. You can use the anti jer also, because it has got a converter which will which should do fine. But well, it's more professional when we know exactly whom the type when we look at the vory right. So let's send to the output this size off the five is sighs, fine bites stands. And when around the program. As you can see, we have got here. Now the size of the fire is 43 bites. But as you can see also well, nothing else happened afterwards. Why? Because look, we set the pointer at the end. And when we do something I do. Why? Fight is not at the end. Ah, why The end of five. Flack doesn't say we are at the end. Do that. Things that are inside here. Well, but we're at the end. So we're not doing anything right now here. And because of that, we should arrest. Set again the pointer. So how to do it? Well, we just need to go again. Said the five seek get and studied at the beginning of the fight. So just type here zero or type here. IOS bag inning. So we're sitting from the from the play from the begging to zero. Okay. Lets around the program. And as you can see, it is everything is working fine. We now know the size of the fire is 43. If you wanted to use the current flag it would work like when we, for example, would read 10 bites. And where if we use something like that and we did something like minus five. So our position he's 10 by 15 bites from the from the begging in from the begging. And after using this, our position is it's then. If you used that way, it will be 20. It's pretty easy and obvious how it works. OK, that's let's go back to the or gene away version off this program. Let's run it. As you can see, everything is working fine. That's all he does. Listen, thank you very much. 7. Writing position pointer - seekp and tellp: Hello, everybody. Today we're going to talk about the writing position pointer and about the functions that can check out Where is the point in? Oh, that again. Things the place off the point. So these functions are called Tell, put and seek boot. The difference between the last functions that we got to know in the last lesson is that there is a world boot, right? So is the only difference. And this function tell tells where is the voting pointer and seek boat set writing, putting pointed at the specified position by us. Okay, so here is also the overloaded function the sick put which takes harmony bites from the flag place. We want to put the putting point in writing position pointer in. So a This is the functions and not with how to use them. Well, first day we have to use the FISA or outward five string. So only did these libraries because these library doesn't have these functions right. And also we should open the fight for the out putting because, well, we're going to write some thinking to the fine. Okay, someone's right. Something to defy. So, for example, let's create a temporary variable. Which Diaby string? And let's say it's here since, like this is text about nothing. So something that let's put it into the five. So just something like that are with around the fire. And here I have got opened. That's fine. And as you can see, we have got to your message. This is text about nothing, so everything works fine. And now let's check out what this Pointer is saying here. So see out. And now let's say five tell where it's the pointer off boutique and now let's around the program. As you can see, the he would have 26 if we can't it here. So 1234567 This is the 26 position here at the end, so it means that we are at the end of the fight. And right now, if I wanted to, for example, change something in the video, I would need to close the fire and open the game. But with their sick, sick put function, we can change this behavior. You can change all the time. We're want to put something right, so let's do it. Let's do something like seek put to the beginning of the fight we can use here. A flag, which is by default, said So we can do it that way. Are we can not use it like that. But that's do it that way. So it look a bit harder. At least we know exactly how it works. Mm. And now let's put something into the fight against So what? For example, change this letter. So it is in upper case, not in lower case. So let's just sender at T It means that right now we are said at the beginning of the fun and you want to change the first letter 30 on and OK, that's all. Let's around the program. Um, something's not working. Oh, I'm so of course we are using the IOS here and we'll bomb. We have to reload the fight. And as you can see, we changed the first letter to the upper case One. Okay, everything is working fine. Dazzling Did lesson. Thank you very much. 8. Extracting characters from files: Hello, everybody. Today we're going to talk about free functions. Get line, Get on. Diego. These functions are used to extract characters from stream not only five, but also from string. For example. We have good their function, get line. This function takes free arguments. Well, it can also take one argument to argument because you we can all meet them. We can keep them. But, well, Muslim. We're using this function with free arguments. The first argument say's where we like to store the variable the content off the extracted , I think from the fight. So, for example, let's try to write something like five dot get line and now we need As you can see here we have got a tip we should send here the place. We would like to start our count from the fight. So let's create it as ah, as you notice, it should be the pointer. So it should be something like at that and ah, but well, we can use the FARC that the name off the area it's really a point, right? So we can do it that way or weaken you created Don dynamic Curry memo mori. But we can also do it that way. So five get line. And here now we're sending the buffer. And now we should say, how many would we would like to get her bites from the fire? So if we types and tonight 50 then we'll get 50 bites in tow. The buffer. Okay, So when you got this program, we got it into the buffer. Now we should send it to the out. As you can see, here we have on the output my name and surname because you know, if I would have good know my name and Sodom and some random two names and some things So it means that we are getting 50 characters from here. But look is my name and Southern 50 characters. 123456789 10 11 12 13 14 15 16 17 18 1920. So it's on the 20 characters Why we didn't get the more characters Because function get line by default has got here something like death. This thing says that it should get 50 characters unless it meets that character which is representing the end off line. It's pretty easy to understand because well, get line means Hey, please get a line from from the fire. You see that five get line is really cool thing. Because normally when we're using the stream, if we did something like that, we would get on Lee. What? One world we wouldn't get two words is one right now. Using the get line function we can do something like that for is pretty easy. So okay, here how good line function looks. The first argument is saying where to store, where to start there extracted contractors. Then Haman characters should be taken unless and here we can say, What is the separator? What is deadly Meter? What is the deal? A meter? Well, it is right now there, beck slash End. But you've used, for example, character a. Then it would stop here because here we have a So when you're not spoken, as you can see, we have got on a key. Okay, so it is just a deli Meter is the separator. It means where it should stop reading the Lyell. Something like that. We can also, for example, say well well, let's get from divine on the 10 characters when you know this program is you can see first in characters. He's just my name. Okay, so this function is a deadline function. What is the get function? Well, this function is pretty the same but there is a small difference difference in that. These think extracts it extracts the buffer. Well, the deli meter the separator and delete it. This think doesn't extracts separating. So what's the problem? Well, should be that way When we run the program. For example, if you wanted to take all characters from the fire, we could write with that function something like doh wide Ah wide Uh and the fire is not in that are we could also do something like that. Why this thing is possible. What can send to the output buffer if you work because get line Ah is true until we something going home is not happening So we have a rarer Then it will return the false. So when we not this program Onda we also know something like that. As you can see, we have got all names and soundings. Do it easy to understand We could all things from the from the fight But if you use these function we would get on Lee first name and sign suddenly. Why is it happening? It is because the get function doesn't extract the separator and look the get function. We'll take as many characters as it is stated in thes place, unless separate Aries meant so each time this function, it's meeting the separator, which is not extracted at all. That's why every time it's not going farther. So if you wanted to, for example, delayed this thing from the end, we could extract it with the ignore function. Ignore function, extracts character. Ah, well, extracts characters. Come on here. We should state how common characters two extra right and to ignore them. And at the end, we have good also as separate. Okay, so right now we should after each time we get something from the PFI, we should ignore Gig No. One character on. As you can see now we can get all of them. So you might be thinking, When should we use these potential? Do we use this the most time you will be using this function, but there might be sometimes situations like, for example, let's exercise these functions that we should we have just learned Let's create a program where we will get from the fire where our names and some names only first letter off the name and only first letter off the seven So Onley initials the name and sound how to do it . It would be wrong to use the guideline them We'll use the get function. Okay, so how to do it? We will get well, Let's get first coup tempering variables first corrector and last character. Well, for the first initial in for the second initial, right, call it second. And now this function the get function also has good one overloaded function that when you use it that way it gets only one character and it returns its character. Good line doesn't have something they did so we can write stuff like first equals five gets And now here. Get here first character can check it out. Let's set the output. Okay. And as you can see, we have good the first character. So it is thes character here and now how to get the second character? How could these character here we should What? We should ignore all these characters on Let's women book as space because we don't know exactly how many characters are here. So we should ignore all possible characters until we meet a space. So we should write something like five that signal and weaken ride big number here. I'm 40 characters until the media space and then we can get second car reactor and so seconds cools. Fight, Get on. No, we are where we are Here and now. We should What? Ignore all possible characters here almost will meet what the end off line conduct. So should again five that you know, for example, that many characters illness will meet and the Blanco and we can send it also through that are put second And now, as you can see, we have good both Carter's here, But we don't need that. You could send it out. Put that away. Okay, It walks. Now let's take all possible character. So we can, for example, well, for all possible initials Dio why fire is not end it. So fire hasn't been on it. And now when we run this program, as you can see, we have got all first initials A W h s and and see. Everything works fine. What if I want it for example, get full name on. Then on the initial it could be possible that somebody who liked into something like that Well, then we would use the cat also Buckley. But for and we'll get how many characters, too to the buffer Onda we would like to take, for example, 50 the characters homeless who meets the and write something that no you have bought for here. Example with at the DOT here. So now we are getting 1st 50 characters on this with me, the space. You know, I don't need to ignore anything. And now, uh, we're getting the first character. How weird work. As you can see, it's working dead wear, um, and why it's not working properly because the kid function is what doesn't. Extracting the separate of the Delhi meter, we need to use the guideline which we extract the separator and they hate it dead way. As you can see now, everything works fine. We have got the name on the any shot off the sound critical. We need to remember that the Gatlin function can be used on industry. No, don't known five. We could also say something like seeing and now that get line. And, for example, I would like to get characters to the puffer on. And I would like to get 50 characters now willing on this program will be asked for something. So when folks are sent to the airport, we'll see. So we need something that now we type something, Um, these type things can be seen him. Well, is schooling about it Is that Look, we can't take more than one world at once. Normally, if you will use something like, for example, dead way, we weren't able to do something like that. We could take on the one or two at once with a deadline. Everything like that is possible. Okay, that's only did listen, thank you very much. 9. Comparing content of two files: Hello, everybody. Today we're going to talk about the Rete function and as you can get it is what it is reading from the fire. But world, these different from the functions that we learned about in the last lesson. Well, this function is reading whatever it ISS plays there and it is not omitting skipping anything. It is not going toe end reading when admit something it just reading the thing like it ISS So it is especially function that is created to read bine Aref ice and there is only one function like that. I mean, there is no overloaded function off the function, so we can only send here as the first argument where to it where we want to safe think that were read and how many bites we want toe read from the file Okay at the beginning will just try to trained this function. But after it will arrive the program which will compare accountant of two fires we'll know if two fights are two different And in addition to this, we can also check if ah, fights are different not only tax fight, but also image fights and other things. Other fights like that What other by notifies So other fights. Okay, so let's try, for example, read everything from the fire and let's send it out. So how to do it by using the Red Faction? Well, firstly, when we use the rate So when we do it like that, we need to. But we need the place to save the things that we all right. So we should create a buffer, a place where we can sort so something like that and well, well, dynamical a located it this time. So new character. And we like to know how in the characters we want to create you. Ah, well, let's not forget also going to deal it and that because otherwise we might have a leak from our program. Let's train again. Something would this cult at the end flak? Because, you know, when the up on the end, at the end of the flock right now we can't exactly say how big is the file, and we can create buffer which will be as big as the fire so we could read it. Wow, at once will tell me so file size. And now we can just type something like five tell Where is they? Get indicator and we cannot create it. The buffer Here we can send the buffer here and now we need to grate on Lee Food Fire and then we consent it the continent do the out now Is it consume? Oh, cups the type of it variables integer Ah, we have some kind of problems. And why is it so? Well, it's a good question because while we are at the end of the fire and you are sea trying to reach something exactly, we're trying to eat 50 character. It's good that I made that mistake by staying because right now we can see that we can repair quit easing just by setting the pointer off the reading at the beginning of five. As you can see now, we read everything properly. But at the end, we have a small problem and why these problem happened. Look, right now we opened if I as a Binah refined, um but we created it as a text file and because of it, it created problems. So if we want to read this it that way by not if I, we should have inserted the names inside Mm. We've by now think firstly, so what? We can do it first. So example can do something pretty fast. Let's open it for out floating. Go. So So just create a new fight which will by not fine. And let's send the input something that on something like that now, as you can see, we have got it cited by nullifying. Now we can. Openness is final. If I also and should walk, you can see now it's working. Fine. Uh, in the game, that's a cute here. So this here. And as you can see now it's everything is working Fine because, well, looks like me in the last less lessons or well, I just inserted things inside using Vicks text melted because of it. There was some kind of some problems with it. The girls. There are some of the show contractors that were red hue with the read because you it is reading everything. Doesn't matter. What is their reading? Everything okay? A za can see now everything works fine. And now let's practice the wheat function. Um, by comparing content of two fights. So how to do something like that? Well, let's delete this thing because we don't know the immediate anymore. And now let's try to check. Defies are equal. How checked? Well, if and let's create a function are fires they call and we'll send here to five. You should also create two fights here, so let's do it that way. Fight one fight too simple. One simple to let's copy it. With the short cuts on, Let's name simple toe So you have good note to five, which ah, a cool. And now, when the 51 is open on in the same time filed two is opened. Then the things that are here who can check if everything is working fine. So let's run the program as you can see fighter open so we can work with them. And no if our feisty call. So we should create a prototype of the function which we return. Bolin. When fight or equal will take you to five. Andi So five streams. So it take to five things here, but fighting doesn't have a copy constructor. So we have to take you. It has a pointer will take pointer to that five. So we open it here and we sent exactly the exact copy. Well, with exact instance off the object here. Right. So we send the five here, um, from this place here. So it's an address. Fight one and address all five to. So if are five equal, then do something. Um, now we should implement these function here. This is not the prototype. So we have to name that fights. Well, we can blame it a and being. So now I have got you a pointer so we can use pretty easy functions by using this kind of operator Andi s, so we can check if ice are equal. I guess it's the best way to check if two fights are the same. If they are equal is the check. If they are the same science firstly, because you know, they are the same size. It means that when they are not the same size, it means they're not equal. And we will not need to check. Bye bye. Why did each character and lose our precious time? However, system the computer time? Eso It's pretty easier to do it that way. Um, but of course, if the equal, if the two fights are equals, for example, like now and somebody change something like that? One character only. Then we should check Bye bye. One by the Czech. Exactly. If something is not well, something is not equal there. Okay, so first of the check this ice, I guess we should create function which would check site size of the fight and off course. We also take here there f stream five stream on. And here when somebody's sent, if I would take it and we will set that seek with the Sikh, get function at the end of a pointer, indicator off the reading and because it said there we can now read the size of filing stories for example, in temporary, very bold and take it with the tell get function. And now we need to remember is very important to back to the begging of five. Because otherwise we might have problems later. Where here We might have problems because we're used advice on Remember the last thing sending the others here. So we're operating off five that are here or that are here when we use when we send them here. So we need to exactly be at the same place where where it was when we send it, right? Well, maybe we should even check worries to fight at the Where is the tile? Get when? When we send a fight here. But what? It would be complicated with him to write a lot of God which is not needed in that simple program. Um, because there are probably thousands off things that we won't probably get away. This is just threatening program. Okay, so let's just said it like that. And now return the size five so size off five return. Okay, so it returns it here, and now we can use it que So ain't five. Size one equals, and you can send their A and fais I still and we can send be Okay, now you might be Why I'm not sending their address, the fires a pointer, so it should take an address. Okay, but a also pointer on and it is pointing to others. So the value of the vory boat is an address. And the value of that for Abel is here. So we are sending really here, and others is a Then take out here here. We have to send an address off fire One. Why? Because when we are sending here and address what we are expecting here and others. Okay, so and we have got here now. Fights That's one equal size of five basis. We have to fight size and we can just check the five size one equals site five size do Then we can easy do something I was we can send to the output. See out. Five are no equal size of fice size of fice not equal and gonna return false. Um so we can send if arf icicles because five are equal. Otherwise we won't say anything because we've sent by such issue something that so now only on this program. As you can see, we have got the message for ice are equal because well, it's returning through by default. Fights are equal. And now when we change some things on Lee one let there as you can see fighter Also he calls So you have to repair it. We have to fix it when fights are equal. We have to check Bye bye bye. But when we for example at here that a single letter as you can see if size off fights are not equal. So it means that fights are just different. Right? Uh so I guess and maybe we can do it. Us. See out five. No, this thing. Something. Okay, So now let's check it by by bite by bite. So it is the hardest part of this program, but well, it's not that hard when we know functional. Great. And we know something like I function. We discovered man Mori compare. So it stands for memory. Compare Ondas you Congrats! It is comparing memory that is indicated by some kind off point of exam. Okay, so we need thes function. We also need to include the strength library And now let's used that star Slim Create a place where we was safe for, For example, when you have a 51 So when they have a fine and we read something went to read it to some kind of place So we can later compare these two values with something that I and be rid. We need to places to store temporary for comparing. So first, let's, I guess do something like that character. Five one buffer equals new character. And now we should use the size of the fight him size of that fight because they are equal. So maybe that's just create you, tempore Variable, which will stay the five size so five size one. And now with this program oh way need to close and dead way 515 through Buffer. Well, of course, we do what we did late it that way because we don't want to have a leak from our program. So I wanted it that way. And now we should say how many buys you want to. It's a buffer size buffer size. So now we have accountant off the Fire one and content on the five to the buffers, and we can compare them. We can compare them with the function that I mentioned in there, which is memory compare, which is comparing whatever data is inside, and we are using memory Come Per and I am sending you 51 buffer and five to buffer. And we also have to say how many bites we want to compare from Bobo that buffers. So we are sending a buffer size and it is very important. Memory Camper is own polls when it's not equal to zero, so when is greater than zero or lower than zero. Well, one is great. And then zero, then 51 batteries has good, simple guns when his lower confined toe buffer has problems. So more couple is working like that. And because of that, we have to on do it the way we have to create the conditions like that. And now well, we consent that fights are not cool and we can also return false. Remember that when we read, um, Falls here way won't be ableto delete, he'll our dynamically allocated memories. So we have to delete it again. Here. Well again for the program. It is the first time in this life off goat because if that condition is met well, this lines won't be around at all. Andi visa versa. They think these lines at 16. 61 won't be executed if the condition off this Ah, this condition is not met. So let's on the program. And as you could see, fights are call wider recall. Because if I recall well, now let's change one character so like that. And let's around the program. As you can see Fighter nautical vice unknown. The same one off the bite was different. Something like that Okay, so let's go to death time when everything was cool. And now let's imagine that this being waas on image well, this program would walk. But now image that date would be, for example, that movie, which would be, for example, free gah bots or maybe even more. Wow, then thes buffer size would be big. Well, as a temporary, very bold take, Frida buys far off memory. Well, some some people maybe don't have even that much. Uh, then it would be a bad idea, right? So we should check the buffer sizes No to its well and big five size. We should created a bit different way. So if five size, it's bigger than, for example, 1024 bites. So it's bigger than one megabyte, then, please, that well, that's created declaration like that. And now let's initialize it here with their not five size but only 1024. Otherwise, buffer size should be equal to fight because, well, when the PFI size is lower than 1024 bites, why should we take 1024 bites? We can take on my example like, right now it's only, um, 40 49 by so way don't need toe. Take one megabyte on and now that's around our program. Ondas. You can see it's working, but the problem is Ah, our fights arm right now, very small. Let's for a second dui dead where the way that we with initialize it with only 10. It means that buffer sizes now lower. So it means that we really read on 10 by 51 and 10 bytes of fighter and we can compare on it to 10 buys of both five. So if, ah, if that first time behind will be equality, if I would be equal. But we need to read all fired one. So we need to work, Rip, it'll that things as long as we do know that the fire So how toe repeat things when you hear the world repeat, we need to remember to repeated with the loops because looks are created for repeating things, so creating do why look, which it is going to execute as long as the 51 we have a good state on the same time 52 will have, which is being this time because sent in Cuba it as a team. We'll have also good state. So we're gonna up. Repeat is as long as it's needed. Okay, so no one runs programs. Fights are cool on when you check into some things that, for example, here As you can see, fights are not equal One off The fight was different. Something waas roll I should say one off. At least one of the bike was different. Okay, so let's go back to the buffer side, which would be great, A bit more professional element because, you know ah, then by this, not much for a fire on. We will need to repeat this thing too many times. If it if I was big. So maybe even one mega by this? No, big. Maybe we should get 10 megabytes. 20 megabytes. It depends on the situation how important this task is and how far we wanted to be. Okay, that's all in the lesson. Thank you very much. 10. Put - loading characters from cin stream directly to file: Hello, everybody. Today we're going to dog about the function we just killed boot. And as you can guess, these function is putting a character on the street, all enlisting so it can be used also on, for example, see out. And it can be also used. The feisty. We need to remember that the fighting must be extreme or the output appstream on. It should use the flag out This. Okay, let's start from the example where we will put something on to see out. Well, let's imagine situation. We have got some kind of text, simple text, which we would like to divide with spaces. So this text is connect it and I don't want it to be connected and more how to do it. How to add space after each off the corrected and Senate adopted we want you don't want to modify this variable. He want to just send it to the out. Okay, so let's use the loop for so we can go to each of the character. Then let's do it that way. If I is lower than their extra length, length is the function that is returning the land of the string and now let's increase it. And now we should put something on the up. So what may be let's let's do something 1st 3 like that. But see out boot? A. When we do something that we'll put on a as you can see, we put an eye here. Ah, at the see out sing so we can put their also each of the characters. So let's do it. See out Put. And now let's And there first character second character, Turk Art until the so, as you can see now have this Texas connected. And now we like to put after Egypt did work. What? Only a small space. Let's put this past. And as you can see now we have a space between each of the correct. Okay, so this is a simple program. Now let's use it on the fighting. Let's imagine situation that I would like to run this program, and I would like to type things here like type characters and all the characters should be inserted put into the fire automatic area, all of them. So how to do it? Well, firstly were for sure going to use the lope so we'll get at each of the character that this put on the council is both inside the fight. So do White. And now do I went? But for example, let's K the correct character of able and anti of the character is, for example, not adopt that. So do why. And now let's take character here so we'll take it with the sea in get function. We're just taking what, one character and it's gonna return into this seat. No. One around this program. As you can see, you can type lots of things when we take that their program is end. So now we can also put something into the fire. And now we can put exactly the sea corrected. Okay, let's run the program and I'm typing a few things and I am typing. Get that. And when I closed it and when I opened fire. As you can see now, he could all the things that we typed here, right? Well, of course you know that thing because it's just here because we send it through the function through the looking, Um, so let's, for example, also do something like that. It's against you. Any type adult that and then type anything after it. We will get on things that are before the top. Okay, that's all in the blessing. Thank you very much. 11. Peek - peeking characters without extracting: Hello, everybody. Today we're going to talk about the pick function. What big picking means. Well, you can imagine Peak as a situation, for example, when a man is looking at the woman neck like they had a looking at it pretty fast and they don't want to be noticed. So it's just picking, looking at something pretty fast, giving the first grains and then looking correct, not being noticed. So picking is just looking fast and how it can be using the program languish. Well, as you can get. It is just looking at character. And then it's not extracting this character, just looking at it. So you know to be noticed and you can use it. Of course. Amanda Stream. So can you see that seeing on you can use it in five? Well, you can, by using the pick function, check if the first character is, for example, in teacher number. Or maybe it is just some kind off text a compactor. You can pretty fast check if you want to. You use it as an integer or as a street, so let's ride a program like that. For example, let's take from the seeing get one character and let's initialize it toe the variable, See? And now, if that see it's greater than that zero from the table asking some some kind of number. I don't remember exactly which one and in the same time see is lower than the nine because 01234567 years next to each other. We have got some kind of set here. So if the numbers are between each other, then we know that this character for she sure is a number, not a not an ABC, which could mean that it is a string, right? So otherwise it's a string. But here it is, an integer. And now we can just do something like that. Get the other thing from the output from the input. Sorry. So things that will be type you for example 54 then, Ah, the rest of the think that would be tight here would go to the scene and then I would go into the number and now we can send it to the art number is Ah, look into something like that. And of course, you can do the same. If it was three, right? So get into something like that. And when you're on this program and types inflict that, as you can see, first character is what extracted from the stream from the input. And we don't want situation. I did. We just wanted in this place what we would. We want it only toe peak to look at it pretty fast and do not extract the number. Now, as you can see, we can pretty easy do something like that on. Say, if something is a text, or maybe it's the number. Okay, that's all in the lesson. Thank you very much. 12. Putback - returning extracted character on stream: Hello, everybody. In the last lesson, we learned about the peak function. Right now we learn about the put back function, which is giving back a character that was extracted from the stream. So let's imagine situation again where we have get function here. And you know what? Typing cure something. And, well, we like to put back one here so we can just write something like scene. Put back the character on the stream. And then, as you can see now, when I type something like that, everything works again. Fine. Now you might be like, Well, but when do you speak when to use? Pulled back. You know, sometimes some people might arrived the cold, for example, using this function and then you need to somehow manage without changing their clothes. And then might be the post bag will be a good idea to use. Right. And for sure, Peking is faster than extracting something and then putting it back from the stream. Right? Or maybe you would like to, for example, not not putting back everything. Maybe you would like to extract the once something and you wouldn't like to put it's back in one situation. But put it back in other situation, right? There might be many things you would like to do. And anyway, this program is not proof. Bullets when you're a need and we do something like that is you concede still a number. We have got some kind of conversion here, but, you know, it's pretty good program. And it might be very fast sometimes because when you write something to the five, for example, you know how things are type there. Exactly. Maybe they are, for example, the diamond like that always. So they have got a deli meter between a space. So if something, something like that, we never happen because you didn't allow it when you were writing to the fight. So it doesn't matter because situations like that won't happen in a way, right? You know what information out there and the taking on the one character instead of going through each off the each of the character is off course faster. Okay, that's all in the lesson. Thank you very much. 13. Write - writing bytes to file: Hello, everybody. Today we're going to talk about the right function and as you can guess by looking at his name, it is what it is writing to the fight ass man and bite as we type. So it's a bit different from the normal operators that we use to insert to riding toe fight , which was that one. So if we have, for example, the array that we will call sample and we have got your simple tax and we have got here five, which is open for are putting and we sender sample and were on the program and we opened if I we'll see that we have got here a sample text on that cynical. So it is no inside. So why do we need another function when we have good? As I said, area this function can write as many bite as we type, so we can have a buffer which we can exactly say how many bites we want to write at once. Or maybe we can maybe want to take on the five characters he right, while 12345 or six characters, we we can exactly say how many characters who want to ride it once. And the cool thing is that it is writing every possible thing. What does it mean? Well, let's use the right function. Five. Right. Well, you need to send here, pointer. So the place where we want to start to write from and how many bites you want toe right inside from that place. Because these appointed point is pointing to the others. Right? So we are now sending here, for example, size off sample. So we're sending here. How, maney. 123456789 10 11. And and now character. So the ending correct. When you run this program, so you will notice. Then we also sent here and our character not only text characters. We could send him any possible think inside. Right? So what? What is different in the right function? You can, for example, send a character that is not ah, that that that we don't have on our keyboard, right? We can send their some kind off by that do not exist exactly in character forms Force, for example. Somebody eaters are in some kind off ankle coding and they don't have the meaning. There but they have exactly meaning for us. When we do some translation, what do I mean? What We can create a low level program, for example, that would compress something. And we like to compress something from, like that. Do something looking different, and it wouldn't mean anything in character for but it would mean something. The bite form and we could interpret it the other way, right? So you want to write a low level programming program? We would use the right function. Or, if we want to say how many characters you want to ride or common at once, we want to create a buffer. Then we would use the right function. So if you type something like that minus one, you'll notice that off course when we refresh it. As you can see, the NAL character has been removed. So a well, we can exactly check harmony off that is inside here. You can see a this 12 I said area. It's 123456789 10 11 and 12 Character now, So it's inserting every possible thing from the beginning where the sample pointer is pointing toe. So that also means that if we type for example, 60 here and we ran this program. As you can see, when we refresh defy, we would do some kind off gal bridge. Ah, we don't know exactly what these that letter at all with a t least I don't know. I've never seen it before because this editor is just a paying it and trying to interpret it because it is a taxi deterrence. Trying to interpret this is the text, but there is some kind of garbage in my Memoria off course when Iran, when you run this program, this garbage will look different way. And because you have some kind of other things there because the's, for example, addresses here can be used by other programs. Or maybe it's just not being used right now. Ah, at all because it was used by other program before there were just some kind of member being using because of it. There is a kind of garbage there, right and disease the finger. And as you can see the right function, right, anything into the fire, it doesn't matter if it's a typical character, right? It bites into the into the fine. Okay, that's all in that lesson. Thank you very much. 14. Gcount - counting characters from last operation: hell over. But today we're going to talk about the G count function. And as you can guess, this function is having name from get character count, which is what getting kind of characters that are being extra acted from the last extraction operation. And now here's the question. Was this extraction operation when we were getting extracting characters from the file? So from the function that great guideline ignore these functions. Ah, then the used with the g count to get how many characters were taken and when would be. When would we be good idea? Toe. Use it. Well, look here we have a name and surname and we'd like to know how many characters are being presented by name and stardom it but once, right? So I don't want to count. 12345 I would like to know exactly that these 25 14 16 or something like that. I like to know exactly how many characters were taken so how to do it. Well, let's create a simple program that we won't get each line until what until we get all the things from the Why so anti we meet world end off there. Fine, right. Well, do why? Fire is not ended. And now we will do fine. Get line. Ah, function which will won't get extract characters from the from the five and we need to save it somewhere. So we need to create a temporary bothersome, for example, with 2200 and 50 and bonds. So it is big one. I'm sure there is no name and sometimes so big and we're sending here a buffer And how many characters we want to get unless we meet What the guideline is were working like that we can meet also an end off line character. So it will get 250 contractors on this imp meets end of fine character. Okay, so ah, right now we consent to the output. Pretty easy that way. And as you can see her, go to your name and surname. Andi. It's working fine. But now I would like to also know how many characters were extracted by each off the deadline. So we need to only do something like G count here on will let it space. So look better. And as you can see, 21 characters are being presented by my name and something 11 by John Sniff 14 by Nikolas Clark I think works fine and it's where the G count function is working the same like get lung function by the same, I mean that it's working on an extreme so we can use it also on C in. And by that you can check how many characters were tied in the council. So when somebody types nothing, the council, you can you can later check how many characters were type pretty easy with it. We've just did function. Okay, there's only good lesson. Thank you very much. 15. Mini database: Hello, everybody. Today we're going to create an many database. What? I mean by me, that date up, It would have basic functions off the comebacks. It will be able tow at some kind of information. In our situation, it will be only people. It will be able to show that people who were able to add these people to save them, toe the fight toe, load them from the fire to said them by, for example, name or to remove a person from their base. So it is the program that we arrive today with all these factions. Okay, so let's start the adventure. What to do we start from I think we should start from the interface. We should communicate somehow with the user. So we should send him a man, right, Manu, something like that. And we should, for example, allow him to do a few things, for example, at person, on what, as we should allow, we should allow him to, for example, show some. I'll show all people inside the dot data and other options that we will at a later. But now we have got a small problem. How to get the OAP option that the guy want to choose, They user well, we can create a temporary variable here, for example, test and we can get it. We, for example, see in get function and later we can switch it test. And if the character is, for example, one, then we can send the output tests. Or you can just invoke function here that would add a person. Right now, we're just writing this program a little eso We're not doing everything like it should be bad. We're just testing, right? So it's test that still, and now we need on this program A. So you can see and was no declared ended function and lying Serie. It's and line When you're on this program, we can now add, persons show people. But when I click something, I need to type enter in order to do something in order to choose something from the men menu. So it's not cool. I would like toa tied one, and it should instantly invoke one off these functions here. How to do it, what we will use the get character function which is not coming from the sea in object. It is inside the library. We discolored like that. And the difference between this and that get function is that it will get immediately the character that this put into the input stream that is waiting for character so well, not when I take one. As you can see, it instantly showed us, Tess, you well, I creek to instantly test do so it's not working. Fine. But now I can't get the problem that the program is ending instantly. How to make it so it won't. And instantly. Well, for example, we can use a look, right? We can do all the time. Things that are inside. Unless, for example, somebody will Creek s Skype on the keyboard. So do why test is not equal to 27. 27 is a number in asking table that 3% escaped on the keyboard. So right now, when you know this program and escape, as you can see, the program is ended. But when I table while, as you can see, we have got here a test. So we invoke something here on. We have got to gay men 11 long Teoh. But one type something wrong on the menu menu appears nothing gets okay So it's not the thing that we would like toa achieve here. Exactly. But now, at this, the program is not ending. How to do it that way that we see the manual. But the things like that here with appear each time we choose something from them menu Well , we can use a function we just called system, and we can use a clear screen option here. Ah C l s stands for clear screen. So it is clearing a screen. And we also have to include this live dysfunction here, which is from the C C standard library and now one around this program. See as Tedy Syria. As you can see now, when I type one to nothing happens when I type anything else. Nothing happens when I type escape. I am getting out of the program. What's going on? Well, there is a small problem that one like league one here. It's taking it to the switch and it's right and it's Output Inc test. But you see, the program is not waiting for for us to see. It just cleaned the screen and again we can see the man you so we should somehow stop the program for a second here So we can allow our user to read this thing here or to do some thinking right so we could wait for him to, for example click Enter. I think it will be the best idea and how to do it. But we can use, for example, loop Why here and use the cat character function. And if that function is not equal to exactly 13 then this function with full and ever be run here. So it means that when I around these now, when the at persons you can see now we have the test here and now I can click every possible character and it will not stop even escape. It's no waiting only for enter now when I kick enter, as you can see. Finally the the thing that was here Waas cleared and again we can see the 13 15 and 16 lines here. So it's not working pretty fine. Ah, so it is just requiring to enter the under. We can create a function here, require enter Onda. We can implement it on before we should ask for enter. So the guy will know what to dio because It would be frustrating if we didn't say he has the trigger. Answer. Right. So click enter too. Counting you? No, As you can see. Mm. Oh, sir, I didn't invoke it. Should invoke it here one is waiting for enter. Nothing as we work. So I have time to read what happened here or do some thinking. Right? Okay, so we have to their working interface. So we should now implement functions, for example, adding function. So let's great you a function, which will they called at person. So this function will add a person to our database. And where we would like to add this person. I think we should start it temporary in our memory. And after it, we could save it to the fire. There is a small problem now how we should ride it. We could use classes. We could use a structure. But, you know, I don't know if all of you know class is good enough. I don't want to confuse you. And because of it, we will use the structures here. Um, which are easier to understand? You can also you can off course change this program toe the classes if you want to train. I think it would be good training of classes if you want. Oh, but right now I would like to show you how toe right to fight, how to load from fights, how to play with them. Right. So because this is the course about the if I it's not about the classes, right? So we will use the structure here, and we're at person by using the structure. So we create a structure and we will call it, for example, person. And this person will be presented by four different values. So, for example, a name which will be string soft Passard name by the age, which can be sure because it is short. It will not be a big number, a string which will represent telephone. Why string? Because in telephone can use sometimes parentheses around and things like that. Right. Okay, so it's looking like that. And now we should create ah variable. Which type would be person, for example, people. And for example, it can be created for 20 of them. So our that database can be bigger than 20. Person, of course. Is Kentucky £5 or something like that body. We take more memory. But above all of these solutions is not good. Because, as you can see, we are in a situation like that losing Memoria In situation like that, we can run into problems somebody want toe inside more people. The best solution to this is something go. This could list vector, but unlikely. We don't know it yet. At least not from the courses that I ah created how we talk about things like that in the next course about the library that allows exactly how how can you store more people more, More things dynamic. Ellie, Um by in professional way right now, we'll use these things here. OK? So clearly created people here for while we created a place for 20 people. And we can add person a new person right now. Here. So, world, first thing we should do, we should ask for data. So, uh, boot, we can ask for name, name, tied, name. See in. And we are getting into the people. And now we should use you some kind of index. Our name. Now what index? We should use it here. I think it should be zero. But later, when we at the first person. It should be one, then two, then freedom for. So I think we should create a global variable that represents how many people were added to the date up. It's so people in data base by default, global variables that are in teacher are zero. So we have got zero here. Now we can send it to the output. So people in data base number of people number off people in database consent eight here. And when we add the person, we should increase it and we should use it as index because at the started will be zero after reading one person to be want until them free. Ah, did we follow what I did? So the bomb balm and Bob so type Name, time, surname and type on age. Um, type telephone. Now we should change also names of rebels and it should ward right now when around this program and we could add person. As you can see, it's not doing anything good because, well, we didn't involve the function, so let's invoke it at birth. One type of name are kaddish, my son Name H telephone click enter to counting you and we added the person, but we can't show them because of it. We should create a function that we show these people well. And we should also say exactly how many people are here because they forgot to divert here . So it's going zero, something like that. It's one. Okay, so let's great the function that we show how many people are in the database. So Voight show people and let's implement it at the end of fire and let's involved it. So we do not forget what I do not forget again with somebody. Victor, I want to show people. Okay. I think that firstly, we should check if people in database it's bigger than zero because, well, what do we want to show if it's not bigger than zero? Otherwise, we would like to send to the output that there is nobody in database. Why the hell are you here? Okay, so people in database and now we can show all of them by just going to all off the people in area. Right? So you want to go through that? I would like to use what look, So let's create a four loop in Teacher I when I is lower than the people in database. Then I plus plus you consent to the output. That person with person index, which is I plus one. Why was I plus one? Because, well, way we could use the eye here. But I think we should use iPods one because, um, it's easier to say to people that in Texas starting from one than from zero on, the programmers understand it. Index is starting from zero. Right? So person in Texas one and then we can type name, which is from people. I that, uh, name that's not Koppett name serving H that that phone on the sub name it's and telephone. Now let's around the program at the person Bam, bam, bam, bam! Shovel people. As you can see, we cannot see them. We can add more off them, show people and as you can see, we can see all of them at once. It will be good idea at your online. Easier to see how it looks like. We could also at end line here so they look, look better And like that'll, Azi casino is looking better. So we cannot persons show people and but the problem is that when you run this program again, nothing is in database. And, well, database is wrong. If you can't load anything from it, he right? Because going a temporary variable right now it's not working could because of it, we should create a database inside. For example, if I we'll store people inside the fire so have to do it well. First, that we should create a function so safe people 25 we should involve that function and we'll added to the manor safe people to find on. Let's involved it case free. Mm safe people. Fine break. And at the end, we should run safe people to fight eso employment function in a day. Okay, so way showed open the five. For saving what? Like that I we should use for opening the fight for sale output 53 We can use fighting, but out with ice cream is used only for putting something inside. So I think it would be a good idea to use that one, and we can call it, for example, database text. We should also include the five stream here library, because otherwise it will not work at all. We should check the file opened prosperous, so five is open. But if fights opened and do something, get otherwise sent to the output that I couldn't create database or safe today, Safety data maze. If I is open, we should not forget to cause the fire. And now we can save something to eat. How we would like to say things to To death five. I think we should save them by, uh like we showed them. So we should send their names are name, age and telephone, name, surname, agent telephone and after eat. When we want to load something from the fight, we'll do the same. We will greet name, surname. Agent telephone would know that each off age off row inside the fight would represent and the person it for each furrows would represent the person. Right? So let's just inserted inside how to do it. I think it will be a good idea to use the group like here. But this time you are writing inside the fight No to the output. So just send everything inside the fight. But what we do know mean the labels here they are. No. Did it needed inside because we're not reading fires user body. It will be threat by computer. So we are insulting inside this thing. I think we should also insert at the start of the five how many people are saved inside. What? How many people are safe in database? Because we can use light of that, um, that variable to load people from date employees. Right. Okay, so let's check. It's working fine. People in database is every thinking. Right now. Up we shoot half, only one enter and off line character. Let's around the program. That's that's a few people. So, for example, myself and for example, Jones me at the person that has so cool name like show all people is he concedes, working fine, safe people to fire. Now I'm closing. Defy when I open it here. As you can see, we have got here now a database with each four roast representing what a new person. And at the beginning we have got how many people are here because we know how many people are here. Now we can read the file and they were free of them. Oh, we can at least showed how many people are in database. We have our reading all the fire, right? So it's easier to read at the beginning that hey, there are three people in the fight. You don't need to read the lighter. All the people then going through all of them and chicken comin off them. Where? Inside. Right. Okay, So show people, that person and we would like to load from the fight. So load people from the from five see out for load people from five case floor and let's implement it at the end. You so how to load? We'll use input. Five stream because it is the library created only four taking things from So that's great if I Well, let's open the FISA worry. We just call database text and we don't need to have any flax here like we didn't that he because flacking input fi stream my beef old is what and the input flak. So we can just read from it. And again, if five is open properly, then can do something. Otherwise we can say that they're five. Database text doesn't exist, Endsley. Okay, But if it exists, then I like to load too. People in database How many people are there? People in database because the first guy but the first line of present how many people were in database, right? And now, if people in database is bigger than zero because maybe there was nobody inside, then there's something otherwise sent it out with data but based ist empty. And though we should take everything from the file, you can do it two different ways. For example, we can create a four lope, and we can go to all of the people inside its site for so we can do it the same like it was down here. But right now we just change where we want to put things from. So we just put the dead way on the show. Look, when you run the program, um, there is no operator like that off coast. We should delayed the and lying corrective soon goes just taking things, inform fire and you can take some beautiful find put inside in one line. Until now, everything works fine when they think for as you can see, what a free people in database and we can see them pretty cool, isn't it? We should inform that Oh, no, people were loaded. Fine. If it proposing. Maybe on and it's been loaded. Okay, so we have good people inside our temporary memory, but you can use other solution. For example, you can do why you haven't read the file yet. So we're using the the flock that is representing into five. And we can do the same inside, but before it, we should create the eye here, load the people. And as you can see, it's also working. No, it's not working. Okay? It is good idea. Good that I didn't want because Well, you could also make a mistake. Like head. Now, do you work for? And as you can see, everything works fine. Why didn't work before? Because he all the time we're trying to put all people in tow on the one person. Right? So that's why it didn't work. Way had all the time. Zero here should increase the I hear each time around it. We around that looks right. Okay. So we can load. People are programming is getting better and better. Now, let's create something even harder. How to search through our database search data base search for a person case five on let's implement the function. So we want to search it that that database now we should check if there is anybody in database. Because why should we look for something that doesn't exist? If people in database is bigger than zero, then something otherwise say that there is nobody in database. What do you want to look for? People in database is greater than zero. So now we can look for simple. I think we can look for somebody by using for example name. So see out, uh, type the name off person. You want to look for something that string name, um, see in name. And them how to look for somebody. I think we could just go through all off the people inside the door. Right? And just check if that name is equal to the name that we type here. So for integer Ah, I equals zero when I is lower than how many people are in the database, and I'd post blast and now a faith. The name that will start here is equal to their name off. One off the person that we, uh, looking Teoh. Then we can just show we could break here if we find the guy on do no look for other people . But, you know, there can be two people on free people with the same name. So we should go through all the people. Unless, for example, we could ask for a second parameter and ask him how many people you want toe see, or something like that. Right? But well, we will just show every person that we the same name. Okay, so how to show it? Oh, I think we should just use the I think that we already created. So we do know, lose our precious time bomb. It's just so it by sos by sending to the person named Solon, Imagine telephone with that at all. Right here. Right. Such for a person? Well, it's first willing to loved everything. Shovel people. Um I would like to find the Jones off. Such for said person. Which name whose name is John. As you can see personally and exist Oh, Jones me Everything works fine. Search for myself. Hello. Here I am. Everything works fine. We can add another persons, for example, myself again will be duplicated to you and oh, Them went around the program again because I didn't load the five. First, you can also load the fire at the beginning. So people from five if you want, so we don't need to loaded the stuff each time to casino people has been loved the properly number of people in database show people Mexican. See, Everybody are there now at the person balm show all people. And now we can save people to fight. We could save those automatic Ari if we want to toe. But maybe it's not good. Always because somebody could make a mistake. And maybe it's good idea to allow somebody to save when he wants to say Okay, so we are saving. And now we want to look for our Kaddish and there you can see now have to people like that , and it's showing both records so everything works fine. Okay, so we can search the database how to remove people from database, does the question. So avoid remove person from date of its see out, remove a person from database case seeks, remove a person from database break bomb, and no, who should implement it? Okay, in the game, if people in database bigger than zero, then we have somebody to remove otherwise, What do you want? To remove you? Right? So there is nothing to remove. What do you want from? They want to take nothing from me. Okay, so, for example, let's remove person by index. Let's take index from somebody them. So who do you want to remove? Type Index online. See in index that's created for April here now, which check if index is well. If people in databases bigger than index because it's no bigger than way, can remove something that doesn't exist while it should be greater or equal to index because, well, if we, for example, wanted toe remove the person of index one will type your one and one person in database is not greater than one. It's equal to one. So in the situation when we have on the one person in database, we would have a problem. Okay, so on now. Oh sent it out. But there is nobody like that now how to remove it? It's a good question that took a dark broke a tower database. You That's, for example, did it this guy how to do it when I did it this thing and do something like that as you can see. Well, we moved all the records after John Smith to that place here. Right? So we could just do stuff, like bomb about them. Them Sam back, Ma'am. Map. Damn, man. But I'm showing you how program can do it, right? Stuff like that. Why, no. Okay, let's go to back today, um, to the picking of the fight like that. Let's do it by using the program. So let's use the for loop. And let's create a key temporary variable, which will start from index on when key slower, then people in database increase key. Now, we must ask why we initialized that variable here with index. Not with zero, because look here. We don't care if you want to remove Jones. Sniff about people that were before you want to just move these guys. Okay, that's what. And now we want to a sign the guy toe that the person that we want to remove persons that are after him, right? People did after him how to do it. We should also remind our says that that index here is what is really 1234567 So it is starting from one but the program program Kelly From what programmer knows that arise starts from zero. Okay, so we should go into the people. And this Something like e minus one. Dark name equals people and the guy after it. So key dog name. Why like that? Because imagine that we have four people in our database. So this thing is what? Before on somebody? Type two. So we have got to you, too. Is to lower than for. He has. So we are moving or removing guy, which is in position to minus one. So one, But because it is in a right, it's really a second guy. So everything works fine on. We are assigning here a guy after it, a guy which isn't 1/3 place, so everything should work. Fine. Okay. So names are name, agent telephone. It's, um, telephone. Mom. People has been loaded. Properly show people. Let's remove a person from database that sweep off my I could want Show that that database . As you can see, I'm not your animal. We should also remember that now we have one person less in our database. So we should what we should There are people in database something like that. I was not the program. Let's show the people in data pays. As you can see, we have four people here. So let's remove a person, for example, myself show all the people Askew can see I disappeared at this from the part first index the Reds removed from data Person from the data business. He moved myself again, and now I do know they exist. Oh, well. But as can see well, you can guess right now it's not saving automatically. So when I loved people from five, I am a game back. So what? We could automatically just to something like safe. You we could just invoke why not to try do it that way. So you know how have to do it. We can just people in a very safe people to fight so we could just show people. Let's remove a person that's removed myself. Shovel people. Hello, people from filing. Unlike that, I did not exist. Okay, So designed that lesson. Now we know how to create and meaning database that is able to add show people save people low. People search four people and remove people from a database. Thank you very much. 16. What after this course: Hello. You might be asking yourself right now. What should I do after dis cars? I think you should learn the STL, which stands for standard Template Library. And it consists off some algorithms, containers, adapters and it aerators. So what is this? STL? It is mostly a library, which consists off containers, managed hive of containers. And there are differences between them and you should know them. You should know how to use them, how to add things there. Even in the last lesson off the scores in the meaning database, I said it would be better to use their content owner to store people in our temporal our memory, right in something like vector or maybe other container. Who knows? But it's better because it is most time ah, easier to retrieve things from there and manage it. So a content container. Ah, pretty far, it's something where you can hold I temps inside where you can hold objects of other objects can hold ah, variables and you can just in operate on them inside. So this is a container, and mostly STL is about Rohinton containers on. Well, I invite you to just read. It may be here. Oh, maybe you can wait for, for example, my calls about this. The stop. Thank you very much for listening to me. Good luck in your adventure off in program.