![]() |
#2
ZQDragon2011-03-01 18:39
|

#include <fstream>
#include <string>
using namespace std;
int main()
{int student[5]={1,2,3,4,5}; ofstream outfile("student.dat",ios::binary);
outfile.write((char*)&student[0],sizeof(student));
outfile.close();
ifstream infile("student.dat",ios::binary);
infile.read((char*)&student[0],sizeof(student));
infile.close();
return 0;
}
打开student.dat文件后,在行的最后面出现乱码,原因?#include <string>
using namespace std;
int main()
{int student[5]={1,2,3,4,5}; ofstream outfile("student.dat",ios::binary);
outfile.write((char*)&student[0],sizeof(student));
outfile.close();
ifstream infile("student.dat",ios::binary);
infile.read((char*)&student[0],sizeof(student));
infile.close();
return 0;
}
谁能详细解释下关于二进制的读写问题?最好举例子!谢谢大家
只有本站会员才能查看附件,请 登录
后面的是神马情况?谢谢大家的回答。
[ 本帖最后由 gmac 于 2011-3-2 17:10 编辑 ]