以下程序中突出显示的行是什么意思

What is meant by the highlighted lines in the below program?

本文关键字:是什么 意思 显示 程序      更新时间:2023-10-16

此处的代码用于创建学生报告卡项目,但是在尝试了解时,我们无法从代码中找出以下行的使用和功能。

这个:

File.read(reinterpret_cast<char *> (&st), sizeof(student));

和此:

int pos=(-1)*static_cast<int>(sizeof(st));

这是主要代码:

File.read(reinterpret_cast<char *> (&st), sizeof(student));
if(st.retrollno()==n)
    {
    st.showdata();
    cout<<"nnPlease Enter The New Details of student"<<endl;
        st.getdata();
            int pos=(-1)*static_cast<int>(sizeof(st));
            File.seekp(pos,ios::cur);
            File.write(reinterpret_cast<char *> (&st), sizeof(student));
            cout<<"nnt Record Updated";
            found=true;
    }
int pos=(-1)*static_cast<int>(sizeof(st));

unsigned int类型转换为整数并否定了它,以计算偏移以在下一行中寻求向后

reinterpret_cast<char *> (&st)

只需将结构的指针转换为char上的指针,因此它与函数原型兼容。但是相同的指针值传递给函数。

因此,此代码倒入文件中的 sizeof(st)字节并写入新结构,更新旧结构。