Hi guys I'm new to this forum and I wanted to ask for some advice on the code that I wrote.
I'm still learning how to code and my teacher asked me to create a static allocated array of structs with a string field: my problem is that i don't really know how to use getline() to fill it and so I get an error from my IDE:
[Error] no matching function for call to 'std::basic_istream::getline(std::string [16]
Here is the code that i used to define the struct:
typedef struct{
string name[16];
int price;
}dish;
And there is the function that I used to fill it:
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;
}
}
I'm sorry if there will be some misspelling but English isn't my main language and I tried to translate the code so that it's easier for you to understand it.
P.S. My IDE is Dev-C++