StrBuf::Set( const char *, int )

Set a StrBuf from a string of a specified length.

Virtual?

No

 

Class

StrBuf

 

Arguments

const char *buf

pointer to the first byte of the string

 

int len

length of the string

Returns

void

 

Notes

Initialize the StrBuf before calling Set().

Exactly len bytes are copied from the string to the StrBuf. The length of the StrBuf is set to the len argument.

Any memory allocated for the StrBuf's buffer 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[] = "xyzzy";
    StrBuf sb;

    sb.Set( chars, 3 );   // set StrBuf from len bytes of char *

    cout << "chars[] = \"" << chars << "\"\n";
    cout << "sb.Text() returns \"" << sb.Text() << "\"\n";
}

Executing the preceding code produces the following output:

chars[] = "xyzzy"
sb.Text() returns "xyz"