StrBuf::Clear()

Clear the length member of a StrBuf.

Virtual?

No

 

Class

StrBuf

 

Arguments

None

 

Returns

void

 

Notes

Only the length member of the StrBuf is zeroed.

To set the buffer member to a zero-length string, call Terminate() after calling Clear().

See also

StrBuf::Terminate()

Example

#include <iostream>

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

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

    sb.Set( "xyz" );

    cout << "Prior to sb.Clear() and sb.Terminate():\n";
    cout << "  sb.Length() returns " << sb.Length() << "\n";
    cout << "  sb.Text() returns \"" << sb.Text() << "\"\n\n";

    sb.Clear();   // zero out the length

    cout << "After sb.Clear() but prior to sb.Terminate():\n";
    cout << "  sb.Length() returns " << sb.Length() << "\n";
    cout << "  sb.Text() returns \"" << sb.Text() << "\"\n\n";

    sb.Terminate();

    cout << "After sb.Clear() and sb.Terminate():\n";
    cout << "  sb.Length() returns " << sb.Length() << "\n";
    cout << "  sb.Text() returns \"" << sb.Text() << "\"\n";
}

Executing the preceding code produces the following output:

Prior to sb.Clear() and sb.Terminate():
  sb.Length() returns 3
  sb.Text() returns "xyz"

After sb.Clear() but prior to sb.Terminate():
  sb.Length() returns 0
  sb.Text() returns "xyz"

After sb.Clear() and sb.Terminate():
  sb.Length() returns 0
  sb.Text() returns ""