I'm new to C++ programming and have really enjoyed learning about it. I've written a function for a larger program. The rest of the program executes, but my compiler (DevC++) says "no matching function for call to `std::basic_string<char, std::char_traits<char>..." even though #include <string> and #include <cstring> are in the header. The char city[] is of CityType --and I don't know what that means, because we haven't been taught that yet. This is what our instructor said "CityType structure is a 2D array holding strings of city names. In this case city[index] is one city...not a single character of a city name. "
Part of this program was already written for us. I just have to be able to work with what we were given. The city names that are in a file (that opens properly) all have underscores. This function must remove the underscores and cout the appropriate city name in the program. Strings are new to me and I'd like to know what I did wrong. Thanks for your help!
//This function removes the underscores from the array of city names.
void removeUnderscores(char city[], int MAX_ARRAY)
{
string cityString(city); //assigns char city[] to string cityString
string space = " "; //creating a variable for the " " space
string underscore = "_"; //creating a variable for the function to look for
for(int i = 0; i < MAX_ARRAY; i++)
{
//This is where my compiler says the problem is. I've tried both
//cityString = cityString.replace(i, underscore, space);
//and cityString.replace(i, underscore, space);
Thank you very much for your response and the reference link you sent.
Yes, I do mean:
string space = " ";
string underscore = "_";
What parameters am I missing? Do you mean the parameters in the cityString.replace ? I thought they were defined earlier--that i steps through the array, underscore = "_" and is what is looked for, and that it is replaced by space = " ", defined above the for loop.