二进制写入文件
程序员文章站
2022-06-12 16:26:27
...
#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”);
}
上一篇: 遍历数组,该怎么解决
下一篇: 盛最多水的容器