如何将数据写如文件再读出来

来源:百度知道 编辑:UC知道 时间:2024/07/06 22:39:31
比如我定义了一个结构体
struct node
{
int a;
char sz[4];
}
node* p = new node;
p->a = 1;
p->sz = "asd";

如何把这个结构体变量写进一个文件
然后又从这个文件中读出来?
我用C++ builder可以用TFileStream实现吗?
请稍微详细的讲一下
不要说可以或不可以就完了

例子 自己修改吧
#include <iostream>
#include <fstream>
using namespace std;
void main(){
ifstream ff;
char ch;
ff.open("e:\\file2.txt",ios::binary);
if (!ff)
cout<<"can not open"<<endl;
else
cout<<ff<<endl;
while((ch=ff.get())!=EOF)
{
cout<<ch<<endl;
}
cout<<ff<<endl;
ff.close();
}

还有参考资料
http://www.cppblog.com/walkspeed/archive/2007/05/02/23325.html