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

C/C++ API Documentation | 2026.1

# StrBuf::Terminate()

Null-terminate the string pointed to by the `buffer` member of a `StrBuf`. The null byte is placed in the buffer at the location indicated by the `length` member.

Virtual? | No |
Class | `StrBuf` |
Arguments | None |
Returns | `void` |

## Notes

Initialize the `StrBuf` before calling `Terminate()`.

The `length` member of the `StrBuf` is effectively unchanged by `Terminate()`.

## Example

`Terminate()` is defined in `strbuf.h` as follows:

    void Terminate()
    {
        Extend( 0 ); --length;
    }

`Terminate()` null-terminates the string by calling `Extend( 0 )`, which also increments the `length` member; the `length` is then decremented within `Terminate()`, leaving it unchanged.

## See also

`StrBuf::StringInit()`

## 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( "xyzzy" );

        cout &lt;&lt; "Prior to sb.SetLength( 3 ) and sb.Terminate():\n";
        cout &lt;&lt; "  sb.Length() returns " &lt;&lt; sb.Length() &lt;&lt; "\n";
        cout &lt;&lt; "  sb.Text() returns \"" &lt;&lt; sb.Text() &lt;&lt; "\"\n\n";

        sb.SetLength( 3 );

        cout &lt;&lt; "After sb.SetLength( 3 ) but prior to sb.Terminate():\n";
        cout &lt;&lt; "  sb.Length() returns " &lt;&lt; sb.Length() &lt;&lt; "\n";
        cout &lt;&lt; "  sb.Text() returns \"" &lt;&lt; sb.Text() &lt;&lt; "\"\n\n";

        sb.Terminate();      // null-terminate the string at length

        cout &lt;&lt; "After sb.SetLength( 3 ) and sb.Terminate():\n";
        cout &lt;&lt; "  sb.Length() returns " &lt;&lt; sb.Length() &lt;&lt; "\n";
        cout &lt;&lt; "  sb.Text() returns \"" &lt;&lt; sb.Text() &lt;&lt; "\"\n";
    }

Executing the preceding code produces the following output:

    Prior to sb.SetLength( 3 ) and sb.Terminate():
      sb.Length() returns 5
      sb.Text() returns "xyzzy"

    After sb.SetLength( 3 ) but prior to sb.Terminate():
      sb.Length() returns 3
      sb.Text() returns "xyzzy"

    After sb.SetLength( 3 ) and sb.Terminate():
      sb.Length() returns 3
      sb.Text() returns "xyz"

Your search for returned results