[英]listfunction doesn't work as expected
I'm trying to list a vector of ingredients. 我正在尝试列出成分的向量。
the class Ingredient only has 2 members and 2 member functions (except for constructor). 该类Ingredient仅具有2个成员和2个成员函数(构造函数除外)。 it holds a name and a category and it has the functions "getName" that returns the name and "getCategory" that returns category.
它包含一个名称和一个类别,并且具有返回名称的函数“ getName”和返回类别的函数“ getCategory”。 these ingredients are then stored in a vector - cabinet.
然后将这些成分存储在矢量柜中。
here is the code that SHOULD list the content of cabinet: 这是应该列出机柜内容的代码:
for(int i = 0; i < cabinet.size(); i++)
{
cout << cabinet[i].getName();
switch(cabinet[i].getCategory())
{
case 1: cout << "Alcohol" << endl;
break;
case 2: cout << "Liqueur" << endl;
break;
case 3: cout << "Brew" << endl;
break;
case 4: cout << "Non alcohol" << endl;
break;
case 5: cout << "Wine" << endl;
break;
}
}
what I get: 我得到的是:
[first ingredient][second ingredient][thrid ingredient]...etc
so, why doesn't my switch-statement work? 那么,为什么我的切换语句不起作用?
Thanks for the help! 谢谢您的帮助! I tried adding
default: cout << cabinet[i].getCategory();
我尝试添加
default: cout << cabinet[i].getCategory();
and found that I accidently stored it as a char. 并发现我不小心将其存储为字符。 fixed the add-function and now it works.
修复了添加功能,现在可以使用了。 Thanks again for the help!
再次感谢您的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.