replace() has many forms. http://www.cplusplus.com/reference/s...g/replace.html
I suspect the first one will suit your needs.
Code:
string& replace ( size_t pos1, size_t n1, const string& str );
For example, this should print 1cat4.
Code:
string original = "1234";
string replace = "cat";
// replace original[1] .. original[2] ("23") with "cat"
original.replace(1, 2, replace);
cout << original;
Hopefully I thought that through correctly . . . and hopefully I've answered your question.
[edit] In your first case, maybe you want something like this.
Code:
string str, str2, str3;
str = "an adequate amount of text";
str2 = "amount of ";
st3 = "";
while(1) {
// search for an occurance of str2 in str
size_t found = str.find(str2);
// if such a substr was found,
if(found != string::npos) {
// replace it with str3
str.replace(found, str2.length(), str3);
}
else break; // if the substring wasn't found, exit the loop
}
See also http://www.cplusplus.com/reference/s...ring/find.html
[/edit]