![](/img/trans.png)
[英]Using C++, how do I read a string of a specific length, from a non-binary file?
[英]How to convert binary read/write to non-binary read/write in C++
我從某處讀取一些C ++代碼,並以二進制格式寫入數據。 我想查看它在文件中的讀寫情況,因此我想將其二進制讀寫轉換為非二進制讀寫。 另外,當我將二進制寫入轉換為非二進制寫入時,我希望它仍然能夠正確讀取信息。 如何才能做到這一點?
寫功能:
int btwrite(short rrn, BTPAGE *page_ptr)
{
// long lseek(), addr;
long addr;
addr = (long) rrn * (long) PAGESIZE + HEADERSIZE;
lseek(btfd, addr, 0);
return (write(btfd, page_ptr, PAGESIZE));
}
讀取功能:
int btread(short rrn, BTPAGE *page_ptr)
{
// long lseek(), addr;
long addr;
addr = (long)rrn * (long)PAGESIZE + HEADERSIZE;
lseek(btfd, addr, 0);
return ( read(btfd, page_ptr, PAGESIZE) );
}
這是BTPAGE的定義:
typedef struct {
short keycount; /* number of keys in page */
int key[MAXKEYS]; /* the actual keys */
short child[MAXKEYS+1]; /* ptrs to rrns of descendants */
} BTPAGE;
在C ++中,將重載的流插入運算符添加到BTPAGE類中。 閱讀BTPage之后,添加以下內容:
cout << *page_ptr << endl;
否則,您將必須編輯您的問題,並提供有關所尋找內容的更多詳細信息。 例如:
另外,請提供BTPAGE的聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.