C++ 二进制文件写操作
生活随笔
收集整理的這篇文章主要介紹了
C++ 二进制文件写操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<iostream>
using namespace std;
#include<fstream>class Person {
public:char m_Name[64]; //姓名int m_Age; //年齡};void test01(){//1、包含頭文件//2.創建流對象ofstream ofs("person.txt",ios::out | ios::binary);//3、打開文件//ofs.open("person.txt",ios::out | ios::binary) ;//4、寫文件Person p = { "張三",18 };ofs.write((const char *)&p, sizeof(Person));//5、關閉文件ofs.close();}//二進制文件寫文件
int main() {test01();system("pause");return 0;
}
我們打開文件的路徑:發現多了一個person.txt文件?
?文件打開就是長下面這個樣子哦
總結
以上是生活随笔為你收集整理的C++ 二进制文件写操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我是一个线程 [转]
- 下一篇: 浅谈HotSpot逃逸分析