160 字
1 分钟
c++代码致使死机3次
2025-10-20
无标签
#include <iostream>
using namespace std;
struct Hero
{
string name;
int age;
string sex;
};
void bubblesort(struct Hero heroArray[], int len)
{
for (int i = 0; i < len-1; i++)
{
for (int j = 0; i < len - i - 1; j++)
{
if (heroArray[j].age > heroArray[j + 1].age)
{
struct Hero temp = heroArray[j];
heroArray[j] = heroArray[j + 1];
heroArray[j + 1] = temp;
}
}
}
}
void printHero(Hero heroArray[], int len)
{
for (int i = 0; i < len; i++)
{
cout << heroArray[i].name << " " << heroArray[i].age << " " << heroArray[i].sex << endl;
}
}
int main()
{
Hero heroArray[5] =
{
{"1",23,"男"},
{"2",22,"男"},
{"3",20,"男"},
{"4",21,"男"},
{"5",19,"女"},
};
int len = sizeof(heroArray) / sizeof(heroArray[0]);
bubblesort(heroArray, len);
}

后来知道j敲成i了,但我没想到死循环会让电脑卡死,以前也写过.😂😂😂

c++代码致使死机3次
https://blog.speechess.dpdns.org/posts/c-plus-plus-issue-crashed-my-pc-thrice/
作者
speechess
发布于
2025-10-20
许可协议
CC BY-NC-SA 4.0
评论