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

C/C++ API Documentation | 2025.2

# StrBuf::operator <<( const StrPtr & )

Append a `StrPtr` to a `StrBuf`. The argument is passed as a reference of the `StrPtr`. The string pointed to by the `StrPtr`'s `buffer` is logically appended to the string pointed to by the `StrBuf`'s `buffer`.

Virtual? | No |
Class | `StrBuf` |
Arguments | `const StrPtr &s` | (implied) reference of the `StrPtr` instance
Returns | `StrBuf &` | reference of the `StrBuf`

## Notes

Arguments are typically instances of classes derived from the `StrPtr` class, such as `StrRef` and `StrBuf`.

Exactly the number of bytes specified by the `length` of the `StrPtr` are appended to the `StrBuf` from the `StrPtr`. The `length` of the `StrBuf` is incremented by the `length` of the `StrPtr`.

If the memory for the `StrBuf`'s `buffer` is not large enough, new contiguous memory is allocated to contain the results of appending the `StrPtr`. If new memory is allocated, the old memory is freed. Any memory allocated is separate from the memory for the `StrPtr`.

## Example

Copy

    #include &lt;iostream&gt;

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

    int main( int argc, char **argv )
    {
        StrRef sr( "zy" );
        StrPtr *sp = &amp;sr;
        StrBuf sba;
        StrBuf sbb;

        sba.Set( "xyzzy" );
        sbb.Set( "xyz" );

        cout &lt;&lt; "sba.Text() after sba.Set( \"xyzzy\" ) returns ";
        cout &lt;&lt; "\"" &lt;&lt; sba.Text() &lt;&lt; "\"\n";
        cout &lt;&lt; "sba.Length() after sba.Set( \"xyzzy\" ) returns ";
        cout &lt;&lt; sba.Length() &lt;&lt; "\n";
        cout &lt;&lt; "sbb.Text() after sbb.Set( \"xyz\" ) returns ";
        cout &lt;&lt; "\"" &lt;&lt; sbb.Text() &lt;&lt; "\"\n";
        cout &lt;&lt; "sbb.Length() after sbb.Set( \"xyz\" ) returns ";
        cout &lt;&lt; sbb.Length() &lt;&lt; "\n";

        sbb &lt;&lt; sr;   // append StrRef to StrBuf

        cout &lt;&lt; "sbb.Text() after sbb &lt;&lt; sr returns ";
        cout &lt;&lt; "\"" &lt;&lt; sbb.Text() &lt;&lt; "\"\n";
        cout &lt;&lt; "sbb.Length() after sbb &lt;&lt; sr returns ";
        cout &lt;&lt; sbb.Length() &lt;&lt; "\n";

        sba &lt;&lt; sbb;   // append StrBuf to StrBuf

        cout &lt;&lt; "sba.Text() after sba &lt;&lt; sbb returns ";
        cout &lt;&lt; "\"" &lt;&lt; sba.Text() &lt;&lt; "\"\n";
        cout &lt;&lt; "sba.Length() after sba &lt;&lt; sbb returns ";
        cout &lt;&lt; sba.Length() &lt;&lt; "\n";
    }

Executing the preceding code produces the following output:

    sba.Text() after sba.Set( "xyzzy" ) returns "xyzzy"
    sba.Length() after sba.Set( "xyzzy" ) returns 5
    sbb.Text() after sbb.Set( "xyz" ) returns "xyz"
    sbb.Length() after sbb.Set( "xyz" ) returns 3
    sbb.Text() after sbb << sr returns "xyzzy"
    sbb.Length() after sbb << sr returns 5
    sba.Text() after sba << sbb returns "xyzzyxyzzy"
    sba.Length() after sba << sbb returns 10

Your search for returned results