C++ 读写文件

Posted 文某9

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++ 读写文件相关的知识,希望对你有一定的参考价值。

#include <iostream>
#include <string>
#include <fstream>
using namespace std;


class Person

public:
	char m_Name[64];
	int  m_Age;
;

void t(void)


	ofstream a;
	a.open("wenmou.txt",ios::binary|ios::out);
	Person wen="宇宙男神文子",100;
	a.write((const char*)&wen,sizeof(wen));
	 


void t2(void)


	ifstream a;
	a.open("wenmou.txt",ios::binary|ios::out);
	if(!a.is_open())
	
		cout<<"打开失败啦"<<endl;
	
	Person wen;
	a.read(( char*)&wen,sizeof(wen));
	cout<<"数据"<<wen.m_Name<<"\\t"<<"年龄"<<wen.m_Age<<endl;
	 


int main(int)

	/*t2();*/
	t2();
	system("pause");



以上是关于C++ 读写文件的主要内容,如果未能解决你的问题,请参考以下文章