c++ - 它不显示数据,它只显示永无止境的循环
问题描述
我得到了一个永无止境的循环。我在这段代码中做错了什么?非常感谢你帮助我。
void viewStudents()
{
student *current = head;
do
{
if(current == NULL)
cout<<"Nothing here."<<endl;
else
{
cout<<"Student Name: "<<current->name<<endl;
cout<<"Student's ID Number: "<<current->studentNum<<endl;
cout<<"Student Degree: "<<current->studentDeg<<endl;
cout<<"Student Year Level: "<<current->studentYearLvl<<endl;
cout<<"Student Contact Number: "<<current->studentCont<<endl;
cout<<"Student Email: "<<current->studentEmail<<endl;
cout<<endl;
current = head->next;
}
}
while(current != NULL);
}
解决方案
问题是您一直设置current
为head->next
.
你想要的是设置current
为current->next
current = current->next;
推荐阅读
- php - 如何将链接转换为 seo 友好的链接?
- javascript - 如果其他情况下,如何使用 html/javascript 复选框函数链接 python
- php - ajax 函数 .done 和 .fail,无值返回
- python - 将 SQL 表命名为与 python to_sql() 函数中的 df 名称相同
- javascript - 三.js 创建镜像 VS。钢材对材料的影响?
- c++ - std::span 迭代器可以比创建它们的 span 对象更长寿吗?
- r - 将周数更改为已过去的周数,而不是一年中的周数
- python - 使用函数的 Python HangMan 游戏
- elasticsearch - Elasticsearch COUNT() 文本字段
- powershell - 我可以使用正则表达式通过 CTRL+R 反向搜索来搜索 PowerShell 命令历史记录吗?