StrBuf::operator <<( const char * )

Append a null-terminated string to a StrBuf. The string is logically appended to the string pointed to by the StrBuf's buffer.

Virtual?

No

 

Class

StrBuf

 

Arguments

const char *s

(implied) pointer to the first byte of the null-terminated string

Returns

StrBuf &

reference of the StrBuf

Notes

The StrBuf's length is incremented by the number of bytes prior to the first null byte in the string.

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

Example

#include <iostream>

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

int main( int argc, char **argv )
{
    char chars[] = "zy";
    StrBuf sb;

    sb.Set( "xyz" );

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

    sb << chars;   // append char * to StrBuf

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

Executing the preceding code produces the following output:

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

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