結構中的結構,我該如何調用內部結構? 我當前的代碼是如何引用嵌套結構?
#include <iostream>
#include <string>
using namespace std;
int N_ITEMS;
int N_SEATS;
struct ST_SEATS{
struct ITM_TYPE {
string name;
float price;
};
};
int main()
{
cout << "Enter number of items: ";
cin >> N_ITEMS;
ST_SEATS seat[3];
seat[1]::ITM_TYPE item[N_ITEMS];
int i = 0;
string name = "";
string input;
float price;
while (i < N_ITEMS)
{
cout << "Input item name: ";
cin >> input;
item[i].name = input;
cout << "item[" << i << "].name SET" << endl;
cout << "Input item price: ";
cin >> price;
item[i].price = price;
cout << "item[" << i << "].price SET" << endl;
i++;
}
i = 0;
while (i < N_ITEMS)
{
cout << "item[" << i << "].name = " << item[i].name << endl;
cout << "item[" << i << "].price = " << item[i].price << endl;
i++;
}
system("pause");
}
我試圖讓每一個座位都有自己的定單收據製造商計劃,基本上是這樣。 我知道,不涉及這個問題來得好,索要更多信息...哦,我差點忘了,錯誤添加
21 E:\Documents\School\Computing\SDD\Assign#2\Projects\random.cpp `::ITM_TYPE' has not been declared
21 E:\Documents\School\Computing\SDD\Assign#2\Projects\random.cpp expected `;' before "item"
30 E:\Documents\School\Computing\SDD\Assign#2\Projects\random.cpp `item' undeclared (first use this function)
我是這麼認爲的需要有行編號功能 – Anycorn 2012-02-23 06:48:03
你所說的「呼叫」意思?我認爲你首先根據你似乎想要做的事來判斷結構是什麼,這讓你感到非常困惑。你必須確定你瞭解事物類型和事物類型之間的差異。 – 2012-02-23 06:50:45
我希望每個座位都有不同的物品和價格列表,我認爲嵌入式結構是實現這一目標的方式。 prehaps嵌入式環和歸零的ITM_TYPE stuct(刪除父stuct到)將用於項目投入,然後座位進步 – Arcticfoxx 2012-02-23 07:02:07