Here is source code of the C++ program which removes a given character from the string. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ Program to Remove given Character from the String
std::cout << "Enter the string : ";
std::cin >> s;
std::cout << "\nEnter the character : ";
std::cin >> c;
/* Removing character c from s */
s.erase(std::remove(s.begin(), s.end(), c), s.end());
std::cout << "\nString after removing the character "
<< c << " : " << s;
$ g++ main.cpp $ ./a.out Enter the string : Mediterranzean Enter the character : z String after removing the character z : Mediterranean
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
If you liked this C++ Program, kindly share, recommend or like below!