我有以下形式的代码:
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();
}
这里两个函数都在同一个程序中,但即使func1
已经stud
关闭,在打开文件时所做func2
的更改也不会反映出来。