Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

C/C++ API Documentation | 2025.1

# StrBuf::Extend( char )

Extend a `StrBuf` by one byte. The string pointed to by the `StrBuf`'s `buffer` is logically extended.

Virtual? | No |
Class | `StrBuf` |
Arguments | `char c` | the byte copied to the extended string
Returns | `void` |

## Notes

One byte is copied to the extended `StrBuf`. The `length` of the `StrBuf` is incremented by one.

`Extend()` does not null-terminate the extended string pointed to by the `StrBuf`'s `buffer`. To ensure that the extended string is null-terminated, call `Terminate()` after calling `Extend()`.

If the memory for the `StrBuf`'s `buffer` is not large enough, enough new memory is allocated to contiguously contain the extended string. If new memory is allocated, the old memory is freed. Any memory allocated is separate from the memory for the byte.

## See also

`StrBuf::Terminate()`

## Example

Copy

    #include &lt;iostream&gt;

    #include &lt;stdhdrs.h&gt;
    #include &lt;strbuf.h&gt;

    int main( int argc, char **argv )
    {
        StrBuf sb;

        sb.Set( "xy" );

        cout &lt;&lt; "sb.Text() prior to sb.Extend( 'z' ) returns ";
        cout &lt;&lt; "\"" &lt;&lt; sb.Text() &lt;&lt; "\"\n";
        cout &lt;&lt; "sb.Length() prior to sb.Extend( 'z' ) returns ";
        cout &lt;&lt; sb.Length() &lt;&lt; "\n\n";

        sb.Extend( 'z' );   // extend StrBuf from char
        sb.Terminate();

        cout &lt;&lt; "sb.Text() after sb.Extend( 'z' ) returns ";
        cout &lt;&lt; "\"" &lt;&lt; sb.Text() &lt;&lt; "\"\n";
        cout &lt;&lt; "sb.Length() after sb.Extend( 'z' ) returns ";
        cout &lt;&lt; sb.Length() &lt;&lt; "\n";
    }

Executing the preceding code produces the following output:

    sb.Text() prior to sb.Extend( 'z' ) returns "xy"
    sb.Length() prior to sb.Extend( 'z' ) returns 2

    sb.Text() after sb.Extend( 'z' ) returns "xyz"
    sb.Length() after sb.Extend( 'z' ) returns 3

Your search for returned results