Hello, welcome to the 72nd tutorial in the c++ programming series. And this problem, we look into how to write to a file. In the previous part, we looked at how to open the file and then show you how to go to a fault. And if the fault exists, it creates the fall when it voids do so if we try and write a number, let's say 45 to a file called Hello dot txt. If the file Hello dot txt, that is why you will do the application that is it will create a file called Hello. txt, then we will write the data to it.
And so what we're gonna do is open up our project. And before we do any coding, like we did in the previous part mission where this data was stored in Xcode for an hour is stored and some will be your studio or whatever you use in you can even Google it. You'll get an answer for that or just messages. And for Xcode, you go to well ESCO preferences, locations, and you go to derive data folder which you can go by clicking this arrow. Then in the folder, you want to form your application, which is c++ for us. And then in here, it's got to build products debug, and in here is the tech for the textbook from the previous tutorial.
Actually, I will just remove these will keep this open so you can actually see it being created. So what you want to do first off, is we're just gonna move this on to STD, our string, foil text file dot txt, so it's going to write to a file called test. Allah txt, and this morning, I need to include a header. There we go just needed the screen header. And what we can do to check if default successfully opens. If folder is open, then what we can do is file less than less damage basically means whatever is to the right This will be the contents of the file, which is tech folder.
Txt. The foil, backslash n so it creates a new line as well. Then we're gonna close the foil witness to a simple statement just printing out that there's been some sort of error on a table to foil generally this erosion curve, but just in case you might want to handle it. So we just open up our folder again, it's created and we could we run it before focus, delete this. Now when I run this application, we have built it. So the debug console didn't pop up.
And nothing was printed in there itself of the default stuff. And they could mean the file was opened successfully. So if we go here, we go to file called test file dot txt. We open it says we have added a file, method C is added a new line as well based on this new line character, why here, they for what into a file, obviously, you can combine this with opening a file so you can go to a forum and some scores, some higher scores and then you can really back in and I used to use the beat the score once again and so forth in the next part of this year is going to be looking at commenting. If you have any questions feel free to message us and support us on our systems Koto UK email will be in the description you can comment on this video or just directly messages via YouTube, or the require links or source code will also be in the description.
And as usual, thanks for watching and I hope you have a great day.