在字符串比较中检查变量用法
CHECK variable usage in comparing of Strings?
void display_a_student(char n[])
{
cout<<"nSTUDENT DETAILSn";
int check=0; ***** WHY ARE WE USING THIS CHECK ??????
fp.open("student.dat",ios::in);
while(fp.read((char*)&st,sizeof(student)))
{
if((strcmpi(st.get_ID_number(),n)==0))
{
st.show_student();
check=1; ----> What is this ?
}
}
fp.close();
if(check==0)
cout<<"nnStudent does not exist";
getch();
}
我不理解代码中的这个"检查"??请尽快告诉我答案:) 这是代码。
这是一个标志。它在此处用于检查用户记录是否存在。如果您看到此代码,
if(check==0)
cout<<"nnStudent does not exist";
你可以看到他们检查它是否为零并打印字符串"Student does not exist"
,这意味着零是默认值。如果存在学生详细信息,则将其设置为 1。该检查在以下代码中完成,
if((strcmpi(st.get_ID_number(),n)==0)) --> This will be true only if student record exists.
{
st.show_student();
check=1; ----> The flag is set here.
}
最后,这个标志不需要总是命名为"check"。 你可以有自己的名字。
我认为编码人员尝试使用检查变量作为一种机制来判断文件中是否存在任何学生记录。
如果未找到学生记录..,则它将打印消息:cout <<"学生不存在";..
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- enum是C++中的宏变量还是整数变量
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 用C++中的一个变量定义一个常量
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 你能重载对象变量名本身返回的内容吗
- 内置函数可查看CPP中的成员变量
- 基模板化类中的 Statiс 变量,C++17 用法
- 在字符串比较中检查变量用法
- 参数和成员变量在构造函数中的用法
- 枚举和静态const成员变量在模板特征类中的用法
- C++14变量模板:它们的用途是什么?任何用法示例
- 在 VC++ 中访问一个文件中声明的变量.(外部关键字用法)
- 当用文字替换变量用法时,程序速度减慢了很多,为什么
- Arduino变量用法
- c++中全局变量的用法
- 函数体中变量强制转换为 void 的这种用法是什么?