我创造了学生的类。这是班级。书面二进制文件在C++中
class student
{
int rollno,marks;
char name[20];
public:
void show();
void get();
int filecreate(const string &,fstream &);
int fileopen(const string &,fstream &);
static int add(const student &,fstream &);
static int read(const student &,fstream &,int);
static int update(const student &,fstream &,int);
int showall(fstream &);
int view(fstream &,int);
int adddummy(fstream &);
};
这是写在二进制文件中的记录我的add方法。
int student::add(const student &s,fstream &fp)
{
fp.seekp(0, ios::end);
if(fp.write((char*)&s,sizeof s))
return 1;
return 0;
}
如果我写入对象的值,写入文件的值是什么。它只是滚动,标记和名称(仅限数据成员?)。现在我想为fstream添加一个成员。加入会员后,如果我写的文件,什么数据写入到文件(将fstream的值也写入文件?)
“文本数据更容易调试,作为一个程序员,你可以用普通的编辑器查看” 如果我作为文本数据存储它很难更新记录,并从文件中删除记录。我可以在文本文件中使用随机访问方法吗? – Heartly
不,您不能在文本文件上轻松使用随机访问。但是,您可以将所有文本文件加载到内存中(如果您的数据不是很大,这是可行的),然后在内存中运行并最终转储文本文件。您也可以使用数据库或(在简单情况下)索引文件,如GDBM。但不要忘记,二进制数据是脆弱的! –
不,我们不关心使用关系数据库系统。我们的后端只有平面文件。那么ISAM呢?无论GDBM是软件还是哈希表等概念? – Heartly