How do you use a pointer-to-struct to get input that will be stored in a string variable? I thought simply passing pz->szCompany to getline() would behave the same as if I had used the . operator on a normal instance of Pizza (instead of a pointer-to), but when I run this program it skips over the company name prompt completely.
// Parts of the program omitted.
struct Pizza {
string szCompany;
float diameter;
float weight;
};
Pizza* pz = new Pizza;
cout << "Enter the weight: ";
cin >> pz->weight;
cout << "Enter the company name: ";
// use getline because the company name can have spaces in it.
getline(cin, pz->szCompany);
cout << "Enter the diameter: ";
cin >> pz->diameter;
cout << "\nCompany name: " << pz->szCompany;
cout << "\nWeight: " << pz->weight;
cout << "\nDiameter: " << pz->diameter;
// cannot forget this step.
delete pz;
return 0;