作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 3D 结构数组创建学校类(class)表。
struct SPS
{
string Class;
string Teacher;
int noStudents;
};
struct SPS array[3][4][5];
概念 View :
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
我希望能够在特定位置输入数组,例如 [1][2][2]
。
这是我当前的代码,但它按预期运行。
cout << "Class:" << endl;
cin >> array[1][2][2].Class;
cout << "Teacher:" << endl;
cin >> array[1][2][2].Teacher;
cout << "Number of students:" << endl;
cin >> array[1][2][2].noStudents;
我正在尝试打印数组,但它没有在输出中显示:
for (int a = 0; a<3; a++)
{
for (int b = 0; b<4; b++)
{
for (int c= 0; c<5; c++)
{
printf("%d\t", array[a][b][c]);
}
cout << "\n";
}
cout << "\n";
}
如有任何帮助,我们将不胜感激。
最佳答案
你不能像那样只输出整个结构。 printf()
不是魔法。编译器应该如何知道要使用什么格式?
只需使用 cout
和 <<
输出结构的每个成员:
for (int a = 0; a<3; a++)
{
for (int b = 0; b<4; b++)
{
for (int c= 0; c<5; c++)
{
cout << array[a][b][c].Class << ' '
<< array[a][b][c].Teacher << ' '
<< array[a][b][c].noStudents << '\n';
}
cout << "\n";
}
cout << "\n";
}
关于c++ - 显示一个三维结构数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50081591/
我在 excel 中有一个具有以下结构的主表: 如何使用 vlookup 功能将其转换为第二张图片所示? (在黄色细胞中起作用)。 现在涉及三个键:白天、用户和数据类型(ADP_ERQ、ADP_SO)
我有一个函数可以搜索一些数据并返回一个 vector : vector findMyData(int byID) { vector tempVect; // do some search...
我正在尝试构建一个 3D Javascript 数组,但我不确定该怎么做,基本上我有 3 个数组,Provinces、Cities 和 Malls 都是连续的,所以我想创建一个 3D 数组来存储所有数
很明显,我提出了一个需要头脑 Storm 的问题。那,或者我太菜鸟了,看不到任何明显的答案: 如何实现一个标签系统,其中每个标签与网站的每个用户都有特定的关系? 我试图实现的一个非常简单的例子是系统跟
我是一名优秀的程序员,十分优秀!