14-07-2007, 21:32
|
|
|
חבר מתאריך: 14.07.07
הודעות: 2
|
|
בעיה ב seekg
אני כותב תוכנית שמטפלת בקבצים. כתבתי פןנקציה כדלהלן:
void Extendhash::readBlock(block &dest, fstream &input, int block)
{
if(!input.is_open())
throw "readBlock(): Input file closed!";
// variables to hold the input data (identical to the variables in the block class)
char blockNumber[5] = {""};
char recordCount[3] = {""};
char blockType[2] = {""}; // "D": data, "B": b-a-t
char depth[5] = {""};
char nextBlock[5] = {""};
char empty[4] = {""};
char data[1000] = {""};
// move the read pointer to the desired block and read its data
input.seekg(block * BlockSize);
input.read(blockNumber, 4);
input.read(recordCount, 2);
input.read(blockType, 1);
input.read(depth, 4);
input.read(nextBlock, 4);
input.read(empty, 3);
input.read(data, 999);
dest.setNumOfBlock(blockNumber);
dest.setBlockType(blockType);
dest.setDepth(depth);
dest.setRecordBlockCount(recordCount);
dest.setNextBlock(nextBlock);
dest.setData(data);
}
באחת הקריאות לפונקציה זו אחרי השורה שהוא עושה seekg נדרסים לי כל הנתונים בקובץ בשאר הפעמים לא.
אם למישהו יש מושג מדוע זה קורה ואיך ניתן לפתור זאת אני אודה לו מאוד.
נפתלי
|