Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cctype>
- using namespace std;
- int main()
- {
- string s = "Today was hot and I had a hot tea";
- string xold = "hot";
- string xnew = "cold";
- int strsub( string s, string xold, string xnew );
- cout << strsub( s, xold, xnew ) << endl;
- return ( 0 );
- }
- string strsub( string s, string xold, string xnew )
- {
- string sum = "";
- bool isqualified = 0;
- for( int i = 0; i < s.size(); )
- {
- if( s.substr( i, xold.size() ) == xold )
- {
- if( isqualified == 0 )
- {
- i += xnew.size();
- sum += xnew;
- isqualified = 1;
- cout << sum << endl;
- }
- }
- else
- {
- sum += s[i];
- i += 1;
- cout << sum << endl;
- }
- }
- return( sum );
Add Comment
Please, Sign In to add comment