C++——处理二进制文件的信息传输过程
发布时间
阅读量:
阅读量
二进制格式的文件内容无法直接通过肉眼进行解读,唯有借助二进制读写操作才能实现其内容的解析。
写入操作:
#include<iostream>
#include<fstream>
using namespace std;
class Person
{
public:
char m_Name[64];
int m_Age;
};
void test()
{
ofstream ofs;
ofs.open("Person.txt", ios::out | ios::binary);
if (!ofs.is_open())
{
cout << "文件打开失败!" << endl;
return;
}
Person p = { "张三", 18 };
ofs.write((const char*)&p, sizeof(p));
ofs.close();
}
int main()
{
test();
sys
全部评论 (0)
还没有任何评论哟~
