Hi everyone.
So in this lesson we will write the code for rating data from a file.
So let's jump directly into code.
So this is my file the name of the file is reading from a file guard CPB.
And this is the folder this containing to file my file would be and read from a file or CBP.
So this is my file my failure to steal it does open this file so it does contain a lot of data.
So let us remove some data
so in all this is the content of the file first string.
The second one is indeed the value and the third one is also a string.
So let's remember now the string in the string so first of all I have to include the file stream fine
stream.
So now we will use the class input file stream.
So I f stream you want to create this object ISIS is the name of the object.
So there's two ways to open the file first is using the constructor.
So my file dot the x.
So this file already exists because we created this file in our last session.
So now we know that first value is actually a string.
So String name second is actually that all number that is in danger.
And the third one is actually a string string.
Basically branch
now taken input.
So I office take name as input then take rule number as input.
Then take branch as input.
So I'm taking the input and after digging the input let us sprint the content.
What is the content.
So we'll see out
first of all what is the name of the student
so after the name that does spring.
Do you remember of the student
and after William but not at the Sprint the branch of the student
so their desks are in our file.
That's another called
so the name is less net row number is today and the branches CSC.
So our code is working correctly.
Now I told you so instead of using the constructor you can do so instead of constructor.
I also have the function open.
So let us use that open function.
So if the stream I office I if it's not open you can give the file name.
So this is the name of the file is my file not the 60
so this will also work fine.
So let's see
solver code is working.
Now I told you you have functions like what you can do you can check with that file exist or not.
So you can write like this.
So if the file exist then you can say the file is opened
fighters opened or you can write file exist so let's test this called
So the file is open.
So this is working.
And the second function was is open function so you can also write this also IFRS Dart is unless code
open and you can print the same thing here
so file is opened
so file is open is getting printed two times.
Correct.
Now one important thing that I'm missing here is after doing all the work we have to close the file.
So my book of the file finishes here.
So let's close the connection.
So if it's not closed function OK.
So this is important.
You have to close the connection.
So let's see so our code is working.
Hundred percent correct.
So this is all about reading from a file.
So in the next review we will discuss about civilization.
So I will see you in the next video by.