#include<iostream>
using namespace std;
struct book
{
char *name;
int
num;
};
class BOOK
{
public:
BOOK()
{
b[0].name = "sdgdsfsd";
b[0].num = 10;
b[1].name = "fsdfdsfsd";
//一个一个的赋值,怎么会有问题啊?????
b[1].num = 2;
b[2].name = "erewrew";
b[2].num = 4;
}
int display()
{
for (int i = 0; i<3; i++)
{
cout << b[i].name << "
" << b[i].num << endl;
}
return 0;
}
private:
book b[3];
};
int main()
{
BOOK b;
b.display();
return 0;
}
//再尝试一下你可以
for (int i = 0; i<3; i++)
做修改就可以啦,崩溃可能是你原本是10,而你数组定义的时候是b[3];就会造成访问资源冲突,就会崩溃
,希望采纳,