C++ Algorithm replace_all_copy()














































C++ Algorithm replace_all_copy()



Header : 
#include <boost/algorithm/string.hpp>

Explanation : 
The user enter any string and replace the given character with replaced character using the replace_all_copy(<string>,<replaceChar>,<replaceWith>)

Sample Program : 
#include <boost/algorithm/string.hpp>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
using namespace boost::algorithm;

int main()
{
    string str;
    cout<<"Enter any string : ";
    getline(cin,str);

    char replaceChar,replaceWith;
    cout<<"Which character replace : ";
    cin>>replaceChar;

    cout<<"character replace with "<<replaceChar<<":";
    cin>>replaceWith;

    cout <<"\n"<< replace_all_copy(str,replaceChar,replaceWith);
    return 0;
}

Output : 
Enter any string :replace all occurrences of a particular of a character from string.
Which character replace : a
character replace a : b
replbce bll occurrences of b pbrticulbr of b chbrbcter from string.

Comments