I have code of form below:
func1()
{
fstream stud("student", fstream::in | fstream::out | fstream::app);
stud << "sameer";
stud.close();
}
func2()
{
string name;
fstream stud("student", fstream::in | fstream::out | fstream::app);
stud >> name;
stud.close();
}
here both functions are in same program but even if func1 has stud closed, on opening the file in func2 the changes are not reflected.
Get rid of
fstream::appfrom your reader. Withfstream::app, the file pointer starts at the end of the file, so you just read an empty string.