Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

C/C++ API Documentation | 2025.2

# StrRef::StrRef( const char * , int ) (constructor)

Construct a `StrRef`, referencing an existing string.

Virtual? | No |
Class | `StrRef` |
Arguments | `char *buf` | a null-terminated string to reference
| `int len` | the string length
Returns | `StrRef` |

## Notes

If arguments are provided, the constructor calls `Set()` with them.

`StrRef::Set()` does not copy the target string; it simply creates a pointer to it. Be sure that the `StrRef` pointing to the target string does not outlive the target string.

## Example

Copy

    #include &lt;iostream&gt;

    #include &lt;stdhdrs.h&gt;
    #include &lt;strbuf.h&gt;

    int main( int argc, char **argv )
    {
        char chars[] = "xyzzy";
        StrRef sr = StrRef( chars, 3 );
        StrBuf sb;
        sb.Set( sr );

        printf( "chars[] = \"%s\"\n", chars );
        printf( "sr.Text() returns \"%s\"\n", sr.Text() );
        printf( "sb.Text() returns \"%s\"\n", sb.Text() );

        return 0;
    }

Executing the preceding code produces the following output:

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

Your search for returned results