我必须使用称为Robot_parts []为每个part_rect结构(PART_NUM,part_name,part_quantity,part_cost)结构阵列与指针
并通过空隙显示功能,我要显示Robot_parts []数组的结构体数组完全通过指针,但我不知道如何,我不知道如何声明Robot_parts []以及是否必须在括号内放置任何数字值。
到目前为止,我有:
#include <iostream>
#include <string>
using namespace std;
void display();
struct part_rec
{
int part_num;
string part_name;
int part_quantity;
double part_cost;
};
int main()
{
part_rec Robot_parts[ ] = {
{7789, "QTI", 4, 12.95},
{1654, "bolt", 4, 0.34},
{6931, "nut", 4, 0.25}
};
return 0;
}
void display()
{
cout<<Robot_parts[]<<endl<<endl;
}
如果我还做了一些其他错误,请让我知道。谢谢!
'COUT << Robot_parts [] << endl << endl;'这不会像你期望的那样工作,C++不能直接打印数组。 –
你认为这应该如何工作:'cout << Robot_parts [] << endl << endl;'??你不是从main()方法调用'display()'。 –
为什么不使用C++容器,例如'vector',而不是一个c风格的数组? – 4386427