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