【发布时间】:2017-11-04 07:41:02
【问题描述】:
我的代码如下。缓冲区有数据,但 fout2.write 不做任何事情。文件已创建,但为空。
ofstream fout2(fname, ios::binary);
fout2.open(fname, ios::binary | ios::in | ios::out);
if (fout2.is_open()) {
//problem is here //write the buffer contents
fout2.write(rmsg.buffer, rmsg.length);
fout2.flush();
memset(rmsg.buffer, 0, sizeof(rmsg.buffer)); //clear the buffer
【问题讨论】:
-
为什么要打开文件两次?
-
只使用 ofstream fout2(fname, ios::binary) if 语句总是返回 false... 所以我添加了 fout2.open(...
-
试试
ofstream fout2(fname, ios::binary | ios::in | ios::out); -
效果不佳
-
它应该工作相同。构造函数的参数被视为与调用
open相同。