Choose Category
#include<iostream> #include<string> using namespace std; int main() { string s1 = "one*two*three";//Given String string s2 = "*";//delimeter string s3 = ",";//string to replace cout << "s1 = " << s1 << endl;//Original String before replace bool flag = true; while(flag) { size_t found = s1.find(s2);//Stores the size of the string by using find() function if(found != string::npos)//its check until the 'n' of the occurence in the given string. { s1.replace(found, s2.length(), s3);//Replace the string using the replace() function } else { flag = false; } } cout << "s1 = " << s1 << endl;//After replacing the string return 0; }