Closed SYQ0312 closed 3 years ago
The crash is in hero_order.exe
(your code) which has nothing to to with RTVS. Looks like null pointer references.
&H[5]
is the problem. You are passing pointer to 6th element of the H
array. You should just pass H
.
如果适用,请简要说明导致此问题的操作:
include
include
include
using namespace std; struct Hero { string name; int age; string sex; }; void bubbleSort(struct Hero H[],int len) { //进行升序排列 for (int i = 0; i < len-1; i++) { for (int j = 0; j < len - i - 1; j++) { if (H[j].age > H[j + 1].age) { struct Hero temp = H[j]; H[j] = H[j + 1]; H[j + 1] = temp; } } } } void PrintHero(struct Hero H[], int len) { for (int i = 0; i < len; i++) { cout << "\t" << H[i].name<<H[i].age<<H[i].sex << endl;
} } int main() { srand((unsigned)time(NULL)); //1.设计英雄的结构体 struct Hero H[5] = { {"张飞",20,"男"}, {"关羽",22,"男"}, {"刘备",23,"男"}, {"赵云",21,"男"}, {"貂蝉",19,"女"} }; //2.进行排序 int len = sizeof(H) / sizeof(H[0]); bubbleSort(&H[5], len);
}//
如果有可说明此问题的任何屏幕截图,请将其一并包含在内,以帮助我们更好地诊断问题。
更多信息:
OS Information Version: Microsoft Windows NT 10.0.18363.0
RTVS Information: Assembly: Microsoft.VisualStudio.R.Package, Version=1.3.40517.1016, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a