Test the zero method of HBufC

Source: Internet
Author: User

Test the zero method of HBufC
Today we see the Zero method of HBufC.

Zero()

IMPORT_C void Zero();

Description

Sets the length of the data to zero.

Set Lenght to 0, and the content does not exist. The following is the test code.

HBufC * aTest = HBufC: NewL (12 );
CleanupStack: PushL (aTest );
_ Partition (KTest, "qijianzhou ");
TPtr = aTest-> Des ();
TBuf <12> aBuf (KTest );
Ptr. append (aBuf); _ encode (KFormat1, "length = % d \ nsize = % d \ ncontent = % S"); console-> Printf (KFormat1, aTest-> Length (), aTest-> Size (), & ptr );
Console-> Getch ();
Ptr. Zero ();
Console-> Printf (KFormat1, aTest-> Length (), aTest-> Size (), & ptr); CleanupStack: PopAndDestroy ();

After testing, we found that the content is cleared and the length is 0.

Test the created length and size.

_ Partition (KFormat1, "length = % d \ nsize = % d \ ncontent = % S ");
HBufC * aTest = HBufC: NewL (12 );
 
CleanupStack: PushL (aTest );
_ Partition (KTest, "qijianzhou ");
TPtr = aTest-> Des ();
TBuf <12> aBuf (KTest );
// Test the length and size after creation.
Console-> Printf (KFormat1, aTest-> Length (), aTest-> Size (), & ptr );
Console-> Getch (); ptr. Append (aBuf); console-> Printf (KFormat1, aTest-> Length (), aTest-> Size (), & ptr );
Console-> Getch ();
Ptr. Zero ();
Console-> Printf (KFormat1, aTest-> Length (), aTest-> Size (), & ptr); CleanupStack: PopAndDestroy ();

After the test, the Length and Size after the creation are both 0 and the content is blank.

If the content length is greater than the specified length when assigning values to HBufC and TBuf, an exception occurs in the program.

 

Anping 2009 @ original
Qi_jianzhou@126.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.