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

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);

}
...全文
209 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.
内容概要:本文围绕“源-荷-储”协同互动的主动配电网优化调度展开研究,以IEEE33节点标准配电系统为基础平台,构建了综合考虑电源侧、负荷侧与储能系统协调运行的优化调度模型。研究重点在于通过引入灵活的供需互动机制,提升配电网对分布式能源的接纳能力与运行经济性,同保障系统安全性与稳定性。文中采用Matlab进行建模与仿真,结合智能优化算法求解多目标、多约束的调度问题,有效实现了削峰填谷、降低网损、提高可再生能源利用率等多重目标,为现代主动配电网的科学调度提供了理论依据与技术支撑。; 适合人群:电气工程、能源动力、自动化等相关专业的研究生、科研人员及从事电力系统规划与运行的工程技术人员。; 使用场景及目标:①应用于含高比例分布式电源的配电网优化调度方案设计;②作为IEEE33节点系统仿真研究的教学与科研案例;③支撑“双碳”背景下新型电力系统中源网荷储协同控制策略的开发与验证。; 阅读建议:建议读者结合Matlab代码深入理解模型构建过程,重点关注目标函数设定、约束条件处理及优化算法实现细节,并可通过修改参数或拓扑结构进行扩展性研究,以提升实际问题解决能力。

65,208

社区成员

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

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