I have found that the STL's replace_if is faster than your method. Here is a sample of its usage.
Code:
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
// Here is our functor
class LetterCheck
{
private:
char test;
public:
LetterCheck( char _test ) : test(_test) { }
bool operator( )( char _test ) { return( test == _test ); }
};
int main( void )
{
string s = "HELLO WORLD";
cout << s << endl;
replace_if( s.begin(), s.end(), LetterCheck('E'), 'I' );
cout << s << endl;
return 0;
}
EDIT: I posted one with a simple standard C style function that checked for a specific letter. Here I replaced the function with a functor and its a little more flexible. Good luck.