StrBuf::operator <<( int )

Append a formatted integer to a StrBuf. The formatted integer is logically appended to the string pointed to by the StrBuf's buffer.

Virtual?

No

 

Class

StrBuf

 

Arguments

int v

(implied) integer

Returns

StrBuf &

reference of the StrBuf

Notes

The integer is formatted with the logical equivalent of sprintf( buf, "%d", v ).

The length is incremented by the number of bytes of the formatted integer.

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

Example

#include <iostream>

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

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

    sb.Set( "xyz" );
    i = 73;

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

    sb << i;   // append (formatted) int to StrBuf

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

Executing the preceding code produces the following output:

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

sb.Text() after sb << i returns "xyz73"
sb.Length() after sb << i returns 5