小编Amr*_*CSE的帖子

reinterpret_cast<char *>(&st) 和 (-1)*static_cast<int> 是什么意思?

此处的代码用于创建学生成绩单项目。在尝试理解时,我们无法弄清楚以下代码的用途和功能:

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

int pos=(-1)*static_cast<int>(sizeof(st));
Run Code Online (Sandbox Code Playgroud)
File.read(reinterpret_cast<char *> (&st), sizeof(student));
if(st.retrollno()==n)
    {
    st.showdata();
    cout<<"\n\nPlease 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<<"\n\n\t Record Updated";
            found=true;
    }
Run Code Online (Sandbox Code Playgroud)

c++ pointers static-cast reinterpret-cast

-1
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

pointers ×1

reinterpret-cast ×1

static-cast ×1