0

我有以下形式的代码:

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的更改也不会反映出来。

4

1 回答 1

1

摆脱fstream::app你的读者。使用fstream::app,文件指针从文件末尾开始,因此您只需读取一个空字符串。

于 2012-08-01T20:55:54.240 回答