How to remove a substring from a given string in C++

1 Answer

0 votes
#include <iostream>
#include <string>

int main() {
    std::string str = "Java C C++ Monty Python";
    std::string substr = "Monty";

    str = str.replace(str.find(substr), substr.length() + 1, "");

    std::cout << str << std::endl;
}

 
 
/*
run:
   
Java C C++ Python
   
*/

 



answered Jun 4, 2024 by avibootz

Related questions

...