如何保持文件打开并从我们上次离开的地方继续?C++
How to leave a file open and continue from where we left last time? C++
有没有办法从文件读入直到一行末尾,然后转到另一个函数做某事,然后返回从同一个文件读入,但从我们上次停止的地方(不是从文件的开头)?
如果是,请提供片段。对我来说,代码比文字更有意义。谢谢
使用 std::fstream::open()
打开文件进行写入时,您可以选择将文件openmode
设置为文件名后面的第二个参数...
std::fstream file;
file.open("myfile.txt", ios_base::openmode::ate);
openmode::ate
是用于打开输入光标位于 eof
的文件的标志。
http://www.cplusplus.com/reference/ios/ios_base/openmode/http://www.cplusplus.com/reference/fstream/fstream/open/http://www.cplusplus.com/reference/fstream/fstream/
相关文章:
- 循环后如何继续阅读
- 我正在尝试使用 c++ 创建一个货币转换程序,我不知道如何继续
- C++:继续创建新的变量可以吗
- 如何继续读取不同功能中的文件,而不是从头开始再次读取文件?
- 在 c++ 中三元运算符中不允许继续(关键字)吗?
- C++ 如何暂停控制台输出,以便用户可以在继续之前阅读信息
- 循环不继续无法弄清楚为什么
- 附加到 gdb 会中断并且不会继续该过程
- C++ 在信号处理程序后继续执行
- 为什么我的Qt程序在断言失败后继续运行?
- 如何打印下一个字母直到 Z 并继续到 A?
- 超时后,线程睡眠不会继续执行
- 使用 ssh 重新连接到远程 Ubuntu 机器后,如何继续使用 gdb 调试 c++ 代码?
- 如何创建一个 while 循环,继续循环,直到在C++中输入'using streams'键?
- 失败后可以继续从流读取吗?
- 在构造函数中删除后继续执行
- 在程序继续C++时保持进程运行
- 继续运行程序而无需任何干预,直到要求退出为止
- while 循环 C++ 结束,但不继续到其余语句
- 即使有例外,希望程序继续继续