C++ examples for STL:string
Use the find, erase, and length member functions of basic_string:
#include <string> #include <iostream> using namespace std; int main(){// w w w. j av a 2 s . co m std::string t = "Banana Banana Banana Banana"; std::string s = "nana"; std::string::size_type i = t.find(s); if (i != std::string::npos) t.erase(i, s.length()); cout<< t; cout<<"\n"; cout<< s; }