struct类型定义数组,如何引用这个数组?
#include <iostream>
#include <cstdlib>
using namespace std;
const int strsize = 20;
struct bop;
void main()
{
bop Person[5];
char C;
int i;
cout << "Please input 5 persons' date:" << endl;
for (i = 0;i < 5; i++)
{
cin >> Person[i].fullname[strsize];
cin >> Person[i].title[strsize];
cin >> Person[i].bopname[strsize];
}
cout << " Menu" << endl;
cout << "a.display by name " << "b.display by title" << endl;
cout << "c.display by bopname " << "d.display by preference" << endl; //打印选项
cout << "q.quit" << endl;
while ((C = getchar()) == 'q')
{
switch (int(C)-64)
{
case 1:
for (i = 0;i < 5;i++)
cout << Person[i].fullname[strsize] << endl;
case 2:
for (i = 0;i < 5;i++)
cout << Person[i].title[strsize] << endl;
case 3:
for (i = 0;i < 5;i++)
cout << Person[i].bopname[strsize] << endl;
default:
cout << "error! please input again!" << endl;
break;
}
}
}
struct bop {
char fullname[strsize];
char title[strsize];
char bopname[strsize];
int preferrence;
};
编译错误是(三种错误):
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2228 “.bopname”的左边必须有类/结构/联合 Test f:\visual studio\test\test\test.cpp 54
错误 C2109 下标要求数组或指针类型 Test f:\visual studio\test\test\test.cpp 52
错误 C2079 “Person”使用未定义的 struct“bop” Test f:\visual studio\test\test\test.cpp 45
#include <cstdlib>
using namespace std;
const int strsize = 20;
struct bop;
void main()
{
bop Person[5];
char C;
int i;
cout << "Please input 5 persons' date:" << endl;
for (i = 0;i < 5; i++)
{
cin >> Person[i].fullname[strsize];
cin >> Person[i].title[strsize];
cin >> Person[i].bopname[strsize];
}
cout << " Menu" << endl;
cout << "a.display by name " << "b.display by title" << endl;
cout << "c.display by bopname " << "d.display by preference" << endl; //打印选项
cout << "q.quit" << endl;
while ((C = getchar()) == 'q')
{
switch (int(C)-64)
{
case 1:
for (i = 0;i < 5;i++)
cout << Person[i].fullname[strsize] << endl;
case 2:
for (i = 0;i < 5;i++)
cout << Person[i].title[strsize] << endl;
case 3:
for (i = 0;i < 5;i++)
cout << Person[i].bopname[strsize] << endl;
default:
cout << "error! please input again!" << endl;
break;
}
}
}
struct bop {
char fullname[strsize];
char title[strsize];
char bopname[strsize];
int preferrence;
};
编译错误是(三种错误):
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C2228 “.bopname”的左边必须有类/结构/联合 Test f:\visual studio\test\test\test.cpp 54
错误 C2109 下标要求数组或指针类型 Test f:\visual studio\test\test\test.cpp 52
错误 C2079 “Person”使用未定义的 struct“bop” Test f:\visual studio\test\test\test.cpp 45
...全文
相关推荐
你必须知道的495个C语言问题
- **对比**:`typedef`更适用于类型定义,而`#define`则更适合定义常量。
你必须知道的495个C语言问题.pdf
**2.2 为什么struct x{}; x theStruct;不对?**直接使用结构体类型定义变量时,必须使用结构体标签,如`struct x theStruct;`。
C++中结构体的类型定义和初始化以及变量引用
"C++中结构体的类型定义和初始化以及变量引用"在C++编程语言中,结构体(struct)是一种复合数据类型,允许我们把不同类型的数据组合到一起,形成一个新的数据结构。这使得我们可以更好地组织和管
struct 结构体中数组和指针的操作
在 struct 结构体中,数组和指针的初始化和赋值都需要特别注意。数组在 struct 结构体中的操作在 struct 结构体中,数组是一种常用的数据结构。
C#中结构体struct和字节数组Byte的之间的转换函数
### 结构体(struct)与字节数组(byte[])转换的重要性在C#中,`struct`是一种值类型,它允许开发者定义自己的数据类型,包含多个字段和方法。


