I'm having trouble deleting strings from an array. The array's max size is 32. Here's my code right now:
void remove_restaurant(string restaurant[], string remove, int current_number) //Not quite right
{
bool found = false;
int max = 32;
for (int pos=0; pos<current_number; pos++)
{
if (remove == restaurant[pos])
{
found = true;
for (int j=pos+1; j<current_number; j++)
{
restaurant[pos] = restaurant[pos+1];
current_number--;
}
cout <<endl<< remove << " was removed."<<endl;
}
}
if (!found)
{
cout << remove<<" was not on the list."<<endl;
}
}
Right now the array size doesn't decrease and I really don't know why. Also, I can't figure out how to deal with multi-word strings. Any ideas at all would be very much appreciated!
In cout <<endl<< remove << " was removed."<<endl; you need to remove the first endl. You can remove the string but like L B said, you can't decrease the size of an array. Once it is allocated, thats the size. If you use a vector, you can increase and decrease the size of that.