首页
学习
活动
专区
圈层
工具
发布

c++文件操作之二进制文件-写文件

代码语言:javascript
代码运行次数:0
复制
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class Person {
public:
    char name[64];
    int age;
};
void test() {
    ofstream ofs;
    ofs.open("person.txt", ios::out | ios::binary);
    Person p = { "张三",18 };
    ofs.write((const char*)&p, sizeof(Person));
    ofs.close();
}
int main() {
    test();
    system("pause");
    return 0;
}
下一篇
举报
领券