在写文件时第一次写入时能实现 ,但删除后再写入的时候就实现不了,为什么?

ruiyiiuo2007 2007-09-04 03:25:07

在写文件时第一次写入时能实现 ,但删除后再写入的时候就实现不了,为什么?
例:
FILE *fp = NULL;
fp = fopen("top.txt","b+");
if(fp)
{
fwrite(szSqlBuffer888,strlen(szSqlBuffer888),1,fp);
fclose(fp);

}
...全文
201 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ruiyiiuo2007 2007-09-05
  • 打赏
  • 举报
回复
多谢谢呀.
xiao_ke 2007-09-04
  • 打赏
  • 举报
回复
是啊 你那個b+ 。。。。。。。
KenYuan2016 2007-09-04
  • 打赏
  • 举报
回复
Please choose the correct parameter in your code...

"r"
Opens for reading. If the file does not exist or cannot be found, the fopen call fails.
"w"
Opens an empty file for writing. If the given file exists, its contents are destroyed.
"a"
Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn't exist.
"r+"
Opens for both reading and writing. (The file must exist.)
"w+"
Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.
"a+"
Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn't exist.
zywhuiss 2007-09-04
  • 打赏
  • 举报
回复
"fp = fopen("top.txt","b+");"
怎么MSDN里面对fopen的说明终没有"b+"这个参数?楼主认真看过MSDN吗?
冷月清晖 2007-09-04
  • 打赏
  • 举报
回复
多些判断 错误处理

if(NULL==(fp = fopen("top.txt","b+")))
/*文件没打开,报错*/
else
/*操作*/
if( 0==fclose( fp ) )
/*文件关闭*/
else
/*报错*/
冷月清晖 2007-09-04
  • 打赏
  • 举报
回复
当然啦,关闭之后要再次打开呀
IfI 2007-09-04
  • 打赏
  • 举报
回复
用c++的话建议用标准c++的库.

这个例子中,你把文件删除了,却没有指定"如果文件不存在就创建它"的参数,所以获取文件指针失败.

按楼上说法,换成wb+试试.
awperpvip 2007-09-04
  • 打赏
  • 举报
回复
debug一下,fp始终为NULL
fopen失败,改一下打开方式,比如传参数为wb+试下OK.
目 录、摘 要 I、Abstract II、目 录 III、第1章 绪论 1、1.1 课题背景 1、1.2 设计原则 1、1.3 研究内容 2、第2章 关键技术简介 3、2.1 Java技术 3、2.2 Spring Boot框架 3、2.3 B/S结构 3、2.4 MYSQL数据库 4、第3章 系统分析 5、3.1 可行性分析 5、3.1.1 技术可行性 5、3.1.2 经济可行性 5、3.1.3 操作可行性 5、3.1.4 间可行性 5、3.2 系统功能分析 6、3.3 系统性能分析 7、3.4 系统流程分析 8、3.4.1注册流程 8、3.4.2登录流程 8、3.4.3购买流程 9、第4章 系统设计 10、4.1 系统结构设计 10、4.2系统顺序图 10、4.2.1登录模块顺序图 10、4.2.2添加信息模块顺序图 11、4.3 数据库设计 12、4.3.1 数据库E-R图设计 12、4.3.2数据库表设计 14、第5章 系统的实现 18、5.1 用户功能模块的实现 18、5.1.1用户注册界面 18、5.1.2用户登录界面 18、5.1.3个人中心界面 19、5.1.4商品详情界面 20、5.1.5购物车界面 20、5.1.6我的订单界面 21、5.1.7我的地址界面 21、5.2 管理员功能模块的实现 21、5.2.1管理员登录界面 21、5.2.2商家管理界面 22、5.2.3用户管理界面 23、5.2.4商品分类管理界面 23、5.3 商家功能模块的实现 24、5.3.1商品信息管理界面 24、5.3.2添加商品信息界面 24、第6章 系统测试 25、6.1 程序测试 25、6.2 测试方案计划 25、6.3 测试方法 26、6.4 测试分析 26、第7章 总结 27、参考文献 28、致 谢 29

65,209

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧