suppose my file contains Names
Nitish
Prudhvi Raj Borra
Rajesh
Srinath
now what the questions i want to update the file i mean i want to append some data in the file suppose i want to enter The Name "Sarath Chandra"
the file should updated in sorted order like this
Nitish
Prudhvi Raj Borra
Rajesh
Sarath Chandra
Srinath
so my method in at first i will store all the words in an vector
string line;
ifstream fin("somefile.txt");
while(!fin.eof()){
fin>>line;//fin
v.push_back(line);//v some be vector name
}
i will also the entered name in vector and sort like this
sort(v.begin,v.end);
and after wards i will open the file in write mode and then copy back the vector contents into the file but this takes so much memory is there any method to update a file without using any extra memory