|
|

楼主 |
发表于 11-5-2008 12:14 AM
|
显示全部楼层
i used autonum to create staff ID automatically and write it into file(.dat)
不懂怎样翻译,抱歉。
fstream file("staffFile.dat",ios::in|ios: ut|ios::binary);
int i=0;
file.seekg(0); //move pointer to 0
file.read((char*)&i,sizeof(int)); //read the data
int pos = file.tellg();
if(pos == -1)
{
file.clear();
}
pos = (sizeof(staff))*i + 4;//4 is size of int, size of empId
file.seekp(pos); //move pointer to correct position for next record
empId=i+1;//empId will increase 1 |
|