二进制写入文件

#include
#include
using namespace std;

//二进制文件 写文件

class Person
{
public:
char m_Name[64];//姓名
int m_age; //年龄
};

void test01()
{
//1.包含头文件
//2.创建流对象
fstream f;

//3.打开文件
f.open("person.txt", ios::out | ios::binary);  //ios::binary 二进制的写入方式


//4.写入文件
Person p = { "张三",20 };
f.write((const char*)&p, sizeof(Person));
//二进制写入文件的方法


//5.关闭文件
f.close();

}

int main()
{
test01();
system(“pause”);
}

猜你喜欢

转载自blog.csdn.net/ADADQDQQ/article/details/108300110