当我尝试使用C编写文件时; fwrite
它接受void
类型作为数据,它不被文本编辑器解释。使用c和C++写入文件
struct index
{
index(int _x, int _y):x(_x), y(_y){}
int x, y;
}
index i(4, 7);
FILE *stream;
fopen_s(&stream, "C:\\File.txt", "wb");
fwrite(&i, sizeof(index), 1, stream);
但是当我尝试使用C++;在二进制模式下流write
,它是可读的。为什么它不会像使用fwrite
写的一样?
听起来像你使用'fwrite'不正确。你可以发布一些代码吗? – 2010-12-12 05:00:17
我发布了'fwrite'。 – user963241 2010-12-12 05:07:57
你的'流'是什么? – chrisaycock 2010-12-12 05:13:00