用write()函数向文本文件写入数据后,打开文件却是乱码!希望各位指点指点!!!
#include<iostream>#include<fstream>
using namespace std;
class Student//学生类
{
public:
Student(float x,float y,float z)//构造函数
{
this->x=x;
this->y=y;
this->z=z;
}
~Student(){}//析构函数
void sum()//计算总成绩
{
cout<<"总成绩:"<<x+y+z;
}
private:
float x;
float y;
float z;
};
int main()
{
Student A(89,90,99);
fstream out("E:\\c++程序数据\\C.txt");
if(!out)
{
cout<<"文件打开失败!";
}
out.write((char *)&A,sizeof(Student));
out.close();
return 0;
}