Hi everyone.
So in this video we are going to learn about civilization.
So what is civilization to civilization is a process of storing and driving the state of an object.
I know the definition is very weird and it is tough to understand.
But first let us write the code and then we will understand with the help of code.
So this is my final situation not CBB.
Now what I'm going to do so obviously I have to include the File f stream
so first let us create a class.
Suppose I want to create a class a student and what I want private properties.
So let's say I want to take three private properties so first is what is the name of the student.
Second is what is the rule number of the student.
And third is basically what is the branch of the student.
And now let us create a constructor
so the student what it will take it will take.
What is the name of the student.
It will take the total number of the student and it will take the branch of the student.
So this is string branch.
Saudi now after doing this.
Let us do so what is my name.
Name is an it is and actually what is the rule number.
So it is odd and the branches be.
So what I want to do so it does create an object first.
So student as one so let's say the name is Doc so rule number is let's say today and the branches let's
say CAC simple.
Now I want to store this object.
So basically I want to store the data in a fine.
So basically I have to use output stream.
Let's say the name of the object is all office.
I want to create a file.
Student dot the 60 and let's say I want to get whatever is present in that fight.
So if you will see basically this is our file folder.
So this is.
So this is and predictably so there is no need to truncate because it will create a new file student
or the extra file will be created.
Now if I want to stored this object store object S1 would I have to do so I have to do something like
this or office s or not name stored.
Name then you have to do something like this or if this is to dot.
So it is.
Rule number.
So this is really no and then you will do well if S S T sorry this is S1 actually S1 and then you will
do all of this S1 and art branch
and finally you will do or if it's not close if I want to store the data in a store not the extra fine
I have to do this but this is very cumbersome process I have to write many lines of code.
So what I want to do so I want that if I will write or if s
s1 so I want to do something like this.
So this line should work.
It should write name.
It should write or number and this line should write the branch inside the file to then dot the 60.
So I want this line to work and it is very obvious.
So for this line to look what we have to do we have to overload this operator we have to overload this
operators on this overload this operator so for overloading the operator what I have to do.
So first of all what is the operator get when we want to overload.
So we want to overload this operator so.
This one I want to overload this operator.
So what it will take it will take an object off f stream glass output file stream glass biodefense let's
say the name is or this it will also take a Student object
biodefense Student object biodefense.
Let's say the name is s.
So you have to write friend in front of it friend.
And what do you write it.
What I will write and so I will have done an object of output file a stream class.
So I want to return an object of our proposed stream class biodefense.
So I want to write an object of this class biodefense so this is written by reference and I am taking
input biodefense so what I have to do.
So basically what I will do I will do all this work inside this function.
So basically I am storing the name.
So here the object the other name of the student is s so I will make it s I am storing the name I am
storing the whole number and I am studying the branch.
And finally I have to return the object biodefense so I will return with this.
So this is all that we have to do now if you will write here.
So if I will write or if this is one to the name of the student is S one.
So if you write or if it's S1 So what will happen.
This piece of code will get executed and our name rule number and branch will get stored.
So this is how it will look.
So let us start program
so we are not printing anything.
That's why our screen is empty.
Now let's see this four letter again.
So I have this student file that does open this flight landed here we have a block party and CSC.
So this is very important concept.
What we are doing so just writing.
We just overloaded this operated and we can do this.
So all this work is basically done inside the class.
And now what I mean is looking very very simple subdomain becomes very simple you can see.
So this is our I mean we are just creating an object.
Then I want to open this file this render the extra file then I am able to do this.
So this is very powerful.
Now similarly I want to read the file.
So for reading the file what I want to do.
So I want to do something like this IFRS S1 again.
So if you want to do this what do we have to do.
So you will overload this operator.
So just like we overloaded this operator we will overload this operator also.
So let us write the code.
So what I want to do I want to create a student let's say S2 then I want to do something like this.
So basically I have to create an object first.
So input file stream let's say the name of the object is a office and I want to read this file student
not the 60 I want to read its content then I want to do something like this.
I f s student as to okay.
So I want to do like this.
I first wrote it s true and then basically what I will do I will print the content where this present
inside is true.
So basically I will do something like this as to dart name
then I will print you limit so Astronaut William
and then what I want to do.
So I also want to print what is the branch
so astronaut bench Okay so I want to do something like this.
ISIS is too.
So again what do we do.
We will overload this operator.
So let's just copy this called
so this time I want to return an object of input file stream biodefense.
I want to overload this operator.
So this is in file stream object.
The name is Isis and I have to pass distributed by defense so that the changes will get reflected here.
Now what I have to do so instead of office I will write a office.
Similarly I office here.
Similarly AFSC
and similarly
so obviously we have to change the operator also take input
and finally what I will do so I will return ISIS.
So this is exactly the same code just like this one.
Here we are writing the data to the file.
And here we are reading the data from the file.
So finally I am returning ISIS.
So here what I am doing.
So this the data that we are reading that will stored that will be stored in this trial and I am printing
the name and printing the rule number and I am printing the branch.
Okay so let us run our program so first of all what will happen.
So this file is already containing this data but we do not need to worry because if you will in this
program what will happen.
So this is with us.
So by default it is by default it is truncate.
So what will happen.
It will delete the old content and it will again stored these values.
So if we do not have to worry and then we are creating this object.
So it will contain all these values and we are printing all these values.
And one more thing.
So after doing the work I have to also close the file.
So I if it's not close.
So let us write our program okay.
So we are getting at this line because you can see so we have written the betterment based construct
benzo a default constructor does not exist.
So that's why we have to create a default constructor so this is a default constructor so it will not
contain anything it is empty just empty so in order to run our program so we are getting error because
he had the name rule number and Valentine actually private.
So we have to make them public if we want to access all these things here.
So when it does make them public so now I think everything should work fine.
So let us turn our program and let's see so you can see the name is Brock the all lambast 30 and the
branches CSC and if you will see the file.
So the file is again containing the same content.
What will happen to first discontent will be deleted.
And again I am writing discontent.
OK so that's how everything is working
so you can see with the help of civilization the code that should belong to the class as belonging to
class now.
So now you can see what I mean has become so much simpler and we are just doing a little book inside
our main function and we are able to achieve this with the help of overloading these two operators.
This an operator and this operator.
So this is the computer code.
If you have any doubt and civilization.
You can definitely ask me.
I will see you in the next one.
Bye bye.