【发布时间】:2019-12-18 10:35:17
【问题描述】:
大家好,我是这个论坛的新手,我想就我编写的代码寻求一些建议。
我仍在学习如何编码,我的老师让我创建一个带有字符串字段的静态分配结构数组:我的问题是我真的不知道如何使用 getline() 来填充它,所以我得到了一个来自我的 IDE 的错误:
[错误] 没有匹配函数调用 'std::basic_istream::getline(std::string [16]
这是我用来定义结构的代码:
typedef struct{
string name[16];
int price;
}dish;
还有我用来填充它的函数:
void insertDish(dish menu[], int fill){
for(int i=0; i<fill; i++){
cout<<"Enter name and price of dish "<<(i+1)<<": "<<endl;
cout<<"Name: ";
cin.getline(menu[i].name);
cout<<"Price: ";
cin>>menu[i].price;
cout<<endl;
}
}
如果有拼写错误,我很抱歉,但英语不是我的主要语言,我尝试翻译代码以便您更容易理解。
附:我的 IDE 是 Dev-C++
【问题讨论】:
-
请比“我的 IDE 出错”更具体。
-
无论你的错误是什么,你一定要阅读Why does
std::getline()skip input after a formatted extraction? -
@molbdnilo 是的,你是对的,我的错误是 ::getline(std::string [16])' >
-
请将您的错误信息添加到问题中。
标签: c++ compiler-errors getline