StrBuf::Append( const char *, int )
Append a string of a specified length to a StrBuf
. The
string is logically appended to the string pointed to by the
StrBuf
's buffer
.
Virtual? |
No |
|
Class |
||
Arguments |
|
pointer to the first byte of the string |
|
length of the string |
|
Returns |
|
Notes
Exactly len
bytes are appended to the StrBuf
from the string. The length
of the StrBuf
is
incremented by the len
argument.
If the memory for the StrBuf
's buffer
is not
large enough, new memory to contiguously contain the results of appending
the string of specified length is allocated. 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[] = "zyx"; StrBuf sb; sb.Set( "xyz" ); cout << "sb.Text() prior to sb.Append( chars, 2 ) returns "; cout << "\"" << sb.Text() << "\"\n"; cout << "sb.Length() prior to sb.Append( chars, 2 ) returns "; cout << sb.Length() << "\n\n"; sb.Append( chars, 2 ); // append len bytes of char * to StrBuf cout << "sb.Text() after sb.Append( chars, 2 ) returns "; cout << "\"" << sb.Text() << "\"\n"; cout << "sb.Length() after sb.Append( chars, 2 ) returns "; cout << sb.Length() << "\n"; }
Executing the preceding code produces the following output:
sb.Text() prior to sb.Append( chars, 2 ) returns "xyz" sb.Length() prior to sb.Append( chars, 2 ) returns 3 sb.Text() after sb.Append( chars, 2 ) returns "xyzzy" sb.Length() after sb.Append( chars, 2 ) returns 5