以下程序中突出显示的行是什么意思
What is meant by the highlighted lines in the below program?
此处的代码用于创建学生报告卡项目,但是在尝试了解时,我们无法从代码中找出以下行的使用和功能。
这个:
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)
字节并写入新结构,更新旧结构。
相关文章:
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 线应该是什么意思
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 表达式"b=(b-x)&x"是什么意思?
- 这个表达是什么意思?
- 此代码验证公式是什么意思?
- 跟踪日志中的T.11803()是什么意思?
- 这个额外的关键字在这个 c++ 类声明中是什么意思?
- * 和 ** 在 C++ 函数声明中是什么意思?
- _T("xyz")是什么意思?
- #define Dbg(fmt,..) (0) 是什么意思? 警告:表达式无效
- 这行代码到底是什么意思?
- 在命名空间名称之前加上 :: 是什么意思?
- 从字符数组的元素中减去'a'是什么意思
- "friend"关键字在C++中是什么意思?
- 减法中的"0"是什么意思?
- 字符数组前面的加号是什么意思?
- 这里的字符串函数是什么意思