【发布时间】:2023-03-18 17:54:01
【问题描述】:
fstream file(file_1.c_str(), ios::out | ios::in | ios::ate); //convert string to const char*
如果文件不存在则出错。 if ( ! file ) = true
fstream file(file_1.c_str(), ios::out | ios::in | ios::app); //convert string to const char*
使用 ios::app seekg 和 seekp 功能不起作用。 file.seekg(4, ios_base::beg);
我想要:
- USER 输入文件名
- 如果不存在则创建文件
- 使用 seekg & seekp;
- 如果再次运行该程序,请不要删除该文件。
【问题讨论】:
-
如果文件不存在,搜索与打开文件有什么关系?有什么问题?