StrBuf::operator <<( const StrPtr * )

Append a StrPtr to a StrBuf. 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) pointer to the StrPtr instance

Returns

StrBuf &

reference of the StrBuf

Notes

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

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

#include <iostream>

#include <stdhdrs.h>
#include <strbuf.h>

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

    sb.Set( "xyz" );

    cout << "sb.Text() prior to sb << sp returns ";
    cout << "\"" << sb.Text() << "\"\n";
    cout << "sb.Length() prior to sb << sp returns ";
    cout << sb.Length() << "\n\n";

    sb << sp;   // append StrPtr * to StrBuf

    cout << "sb.Text() after sb << sp returns ";
    cout << "\"" << sb.Text() << "\"\n";
    cout << "sb.Length() after sb << sp returns ";
    cout << sb.Length() << "\n";
}

Executing the preceding code produces the following output:

sb.Text() prior to sb << sp returns "xyz"
sb.Length() prior to sb << sp returns 3

sb.Text() after sb << sp returns "xyzzy"
sb.Length() after sb << sp returns 5