Using an array, you could treat empty array cells with a char* such as "EMPTY". To find an item you search through the array , and find to "replace" or add it.
const char * Empty = "EMPTY";
cout << "Please enter a city you want to add:"
cin >> city;
for(int i = 0; i < Arr_Size; i++) //variable to represent size of array
{
if(Arr[i] == Empty) //check for any empty cells you want to add
{
//replace cell
}
else if(i == Arr_Size-1) //if on last loop
cout << "Could not find empty cell, sorry!";
}
As for removing a cell:
cout << "Please enter the name of the city you would like to remove: ";
cin >> CityRemove;
for(int i = 0; i < Arr_Size; i++)
{
if(Arr[i] == CityRemove)
{
Arr[i] = Empty; //previous constant to represent your "empty" cell
}
else if(i == Arr_Size - 1) //on last loop, tell the user you could not find it.
{
cout << "Could not find the city to remove, sorry!";
}
}
Printing the array while skipping the 'empty' cells
//Printing the array
for(int i = 0; i < Arr_Size; i++)
{
if(Arr[i] != Empty) //if the cell isnt 'empty'
{
cout << Arr[i] << endl;
}
}
But i do agree using a vector would be a much more efficient approach, this is simply a creative approach to get your mind thinking.
teamsarray. Also, as mentioned below, using[]doesn't make the array variable-length; it makes its length depend on the length of the initializer list, in this case 4. From that point on, it's the same as a fixed-length array.std::vectoris what you really want."St. Louis,"should be"St. Louis".