I have a very confusing homework assignment that I am not sure how to do correctly. The assignment asks to complete a C++ function to parse a string and swap all occurrences of the substring oldStr with instances of the string newStr. The inputStr may need to change in size due to the result of the replacement...meaning that oldStr and newStr do not have to be the same size. A function header is provided. I think that it is a search and replace function but I am not sure if that is even a correct assumption. I also get errors that inputStr must have a class type? And left of .find and .replace must have class/struct/union? Any suggestion would be greatly appreciated.
void parseSwap( char* inputStr, const char* oldStr, const char* newStr )
{
size_t oldStrLength = strlen(oldStr);
size_t newStrLength = strlen(newStr);
size_t position = 0;
while ((pos = inputStr.find(oldStr, position)) != string::npos)
{
inputStr.replace( position, oldStrLen, newStr );
position += newStrLen;
}