写二进制文件和写普通文件的不同点:
代码示例如下:
#include<iostream>
using namespace std;
#include<fstream>
#include<string>
class Person
{
public:
char m_Name[64];
int m_Age;
};
void test01()
{
ofstream ofs("我家咯咯.txt", ios::out | ios::binary);
//ofs.open("我家咯咯.txt", ios::out | ios::binary);
Person p = { "菜虚坤", 18 };
ofs.write((const char*)&p, sizeof(p));
}
int main() {
test01();
}
文件就创建好了(方块是因为二进制 ,读的时候会还原):