Image

Imagesparkymark wrote in Imagecpp

STL advice sought, please

Recently I have been escaping strings in C++ and have resorted to writing C...
void encode( const char* input, char **output ) // prefix capital letters with '/'.
{
   const size_t length = strlen( input );
   *output = new char[ 2 * length + 1 ];
   char *p = *output;
   for ( size_t i = 0 ; i < length; i++ )
   {
      if ( input[ i ] >= 'A' && input[ i ] <= 'Z' )
      {
         *p++='/';
      }
      *p++=input[ i ]; 
   }
   *p='\0';
}
Is there a way I could be doing this with STL iterators? (I know I should avoid using a bare new[] but this is just prototype code).
Edit These are all great, thanks. I'm sure there must be scope for some additional for_each functor madness but this is all I needed.