大家好,请问这个c++程序是哪里有问题,版本是vs2017,项目属性字符集已改成使用多字节字符集,但是仍然显示错误:
#include<iostream>
using namespace std;
#include<string>
//1、设计英雄结构体
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; j < 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(struct hero heroArray[], int len)
{
for (int i = 0; i < len; i++)
{
cout << " 姓名: " << heroArray[i].name << " 年龄: " << heroArray[i].age
<< " 性别: "<< heroArray[i].sex <<endl;
}
}
int main()
{
//2、创建数组存放5名英雄
struct Hero heroArray[5] =
{
{"刘备",23,"男"},
{"关羽",22,"男"},
{"张飞",20,"男"},
{"赵云",21,"男"},
{"貂蝉",19,"女"},
};
int len = sizeof(heroArray) / sizeof(heroArray[0]);
//for (int i = 0; i < len; i++)
//{
// cout << " 姓名: " << heroArray[i].name << " 年龄: " << heroArray[i].age
// << " 性别: "<< heroArray[i].sex <<endl;
//}
//3、对数组排序
bubbleSort(heroArray, len);
//打印数组
printHero(heroArray, len);
system("pause");
return 0;
}
标红代码始终有问题,请问如何修改