From the suggested answer Why does std::getline() skip input after a formatted extraction? getline() is not working for the follwing code but cin>>ws . Can anyone explain why?
Problem: In this I have created a class Restaurant and created its object pointer *my_restaurant. I'm trying to set data in object from user input and show it in output. But its not working, properly. What should i do? Output is shown in attached image. Thanks in advance
#include<bits/stdc++.h>
using namespace std;
class Restaurant
{
public:
int food_item_codes[12];
string food_item_names[12];
int food_item_price[12];
int total_tax;
};
int main()
{
Restaurant *my_restaurant = new Restaurant;
int n;
cin>>n;
for(int i = 0; i<n; i++)
{
cin>>my_restaurant->food_item_codes[i];
getline(cin,(my_restaurant->food_item_names[i]));
cin>>my_restaurant->food_item_price[i];
}
cout<<"Make Bill"<<endl;
cout<<"Item code \t\t\t\t"<<"Item Name \t\t\t\t"<<"item price"<<endl;
for(int i = 0; i<n; i++)
{
cout<<my_restaurant->food_item_codes[i]<<"\t\t\t\t";
cout<<my_restaurant->food_item_names[i]<<"\t\t\t\t";
cout<<my_restaurant->food_item_price[i]<<endl;
}
return 0;
}