readme.txt
来自「A template solution for C++ database dev」· 文本 代码 · 共 51 行
TXT
51 行
Use this class in the following manner (where MY_TYPE is a class or structure written by you)
Adding a record:
*************
MY_TYPE mt;
// Set values of mt member variables
DataStore<MY_TYPE> ds("my.dat");
if(ds.Open()) {
if(ds.AddRecord(mt)) {
cout<<"Record saved"<<endl;
}else {
cout<<"Failed to save record"<<endl;
}
ds.Close();
}else {
cout<<"Failed to open file"<<endl;
}
*********************************
~~~~~~~~~~~~~~~~~~~~~~~~~~
Finding number of records in a data file:
******************************
DataStore<MY_TYPE> ds("my.dat");
if(ds.Open()) {
unsigned long recs = ds.GetRecordCount();
}
***********************************
~~~~~~~~~~~~
Deleting a record:
*************
unsigned long index = 0;
for(unsigned long i=0;i<recs;i++) {
mt = ds.FindRecord(i);
// compare a field of mt against a search value
if (comparison is true) {
break;
}else {
index++;
}
}
ds.DeleteRecord(index);
// ds.ModifyRecord(new_mt,index);
ds.Close();
***********************************
DataStore has a member function called GetNextRecordNo() which can be used to generate
a unique long id for the next record to be written.
This function can be used for getting an id for uniquely identifying a record in the file.
For this a class that serializes itself using DataStore should have an unsigned long field in it.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?