C++ 结构内部的结构数组,C++;代码

C++ 结构内部的结构数组,C++;代码,c++,structure,C++,Structure,我正在为最终将成为泥浆的东西准备一些代码;这是我的第一个“大”项目,我正在逐步消除错误;然而,一些问题现在阻碍了我的项目,我似乎无法打破它们。这是我的密码: #include <iostream> using namespace std; int test_var; #define K 125 #define TEST 50 struct item { int quantity; //Some More Stuff Will Be Inside Later// }; st

我正在为最终将成为泥浆的东西准备一些代码;这是我的第一个“大”项目,我正在逐步消除错误;然而,一些问题现在阻碍了我的项目,我似乎无法打破它们。这是我的密码:

#include <iostream>
using namespace std;

int test_var;
#define K    125
#define TEST 50

struct item {
int quantity;
//Some More Stuff Will Be Inside Later//
};

struct inventory {
  struct item[K];  //Error 1 - "expected unqualified-id before '[' token"
} test;

int main()
{
cout << "Number?" << endl;
cin >> test_var;
test.item[TEST].quantity = test_var;  //Error 2 - "'struct inventory' has no member named 'item'"
cout << test.item[TEST].quantity << endl;  //Error 3 - "'struct inventory' has no member named 'item'"
cout << test.item[TEST].quantity;  //Error 4 - "'struct inventory' has no member named 'item'"
return 0;
}
#包括
使用名称空间std;
int-test_-var;
#定义K125
#定义测试50
结构项{
整数;
//稍后会有更多的东西在里面//
};
结构清单{
结构项[K];//错误1-“['标记之前应为非限定id”
}试验;
int main()
{
cout检验;
test.item[test].quantity=test\u var;//错误2-“'struct inventory'没有名为'item'的成员”
库特
您缺少结构对象的标识符/名称。请注意,
item
本身是一个结构。因此,请重试

struct item obj[K];  // struct key word is unnecessary
您缺少结构对象的标识符/名称。请注意,
item
本身是一个结构。因此,请重试

struct item obj[K];  // struct key word is unnecessary

结构项[k]中的第一个错误是您没有为该项指定名称。请尝试以下操作:结构项名称[k]。结构项[k]中的第一个错误是您没有为该项指定名称。请尝试以下操作:结构项名称[k]