在不关闭程序的情况下写入文件后,从文件中获取保存的数据
get saved data from files after writing into them without closing the program
我有下面的表单代码:
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
中打开文件时,更改也不会反映出来。
从阅读器中删除fstream::app
。对于fstream::app
,文件指针从文件的末尾开始,因此您只需读取一个空字符串。
相关文章:
- C++ - 忽略并从其他文件获取数据
- 为什么从文件获取图标时应用程序有时会崩溃?
- 如何在 c++ 窗口中将参数和返回的退出值传递到批处理文件/从批处理文件获取返回的退出值
- Qt .pro 文件获取 Qtkit 名称
- 提升属性树:如何使用xml文件获取子树的子级
- 从C 中的二进制文件获取整数值时
- 如何在Windows上绕过主机文件获取真实的IP地址
- 如何使用 CPP/C# 从 VHDX 文件获取文件(或文件系统)
- 从读取到对象指针数组的文件获取段错误
- 是否可以从IOS项目中的cpp文件获取文件路径
- 将数据从头文件获取到源文件中的非成员函数中
- 从两个不同的文件获取输入时,输入会发生变化
- 从文件 C++ 获取整数
- 通过在 C++ 中使用发布模式二进制文件获取崩溃原因
- C++ 将值从文件获取到数组中
- 使用HTTP上载文件.获取错误:-HttpSendReuest 12005
- 正在从外部文件获取输入
- 读/写同一个文件(获取gmon.out)
- 从二进制文件获取输入时发生访问冲突错误
- 从特定文件获取函数指针