In the code below, I'm attempting to output a list of pizza toppings using the getToppings() method. I'd like to clear this listing of toppings at the end of each inner 'while' loop (i.e. each new pizza order must be initiated with no toppings). Unfortunately, I have found no way to clear my listOfToppings string. When I explicitly use the .clear() method, the last topping of the previous pizza is transferred to the new pizza. How can I clear the listOfToppings for each new pizza?
int main()
{
PizzaOrder pizza;
string size;
string toppingSelection;
bool innerLoop = true;
bool outerLoop = true;
int currentToppingsNum;
// Outer loop
while (outerLoop)
{
// Outer loop
...
// Inner loop
while (innerLoop && currentToppingsNum < 5)
{
pizza.PizzaOrder::getToppings(list);
cout << "Current Pizza: " << pizza.stringizeSize() << list << "\n\n";
cout << "Select an item by number (0 when done): \n\n";
...
cout << "Selection: ";
...
...
pizza.displayPizza();
} list.clear();
}
return 0;
}
...
void PizzaOrder::getToppings(string &listOfToppings)
{
for (int i = 0; i < numToppings; i++)
listOfToppings = listOfToppings + " + " + toppings[i];
}