Question: Object: When it finds an occurrence of string2, it should replace it with string3 and save the result in a new string string4. For example,

Object:

When it finds an occurrence of string2, it should replace it with string3 and save the result in a new string string4.

For example, suppose the three strings have the following values:

String1: the dog jumped over the fence

String2: the

String3: that

The new string object will have the value that dog jumped over that fence.

Need help fixing my error in C++?

#include #include

using namespace std;

string replaceSubstring(string str1, string str2, string str3);

int main() { string one; string two; string three;

cout << "string1: " << endl; getline(cin,one); cout << "string2: " << endl; getline(cin,two); cout << "string3: " << endl; getline(cin,three);

// cout << one << endl; replaceSubstring(one, two, three); cout << replaceSubstring(one, two, three) << endl;

return 0; } string replaceSubstring(string str1, string str2, string str3) { string four; for (int x = 0; x < sizeof(str1); x++) { str1.find(str2); str1.replace(0, str2.length(), str3); } for (int x = 0; x < sizeof(str2); x++) { str2.find(str3); str2.replace(0, str3.length(), four); } return four; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!