Cstring class usage and self-written cstring class

Source: Internet
Author: User

cstring is based on the tchar data type. if the symbol
_ Unicode is defined for your program, tchar is defined as type
wchar_t , a 16-bit character type; otherwise, it is defined as
char , the normal 8-bit character type. under Unicode, then,
cstring objects are composed of 16-bit characters. without Unicode, They
are composed of 8-bit char type.

When not using_ Unicode,CstringIs enabled for multibyte
Character sets (MBCS, also known as double-byte character sets, DBCS). Note that
For MBCS strings,CstringStill counts, returns, and manipulates strings
Based on 8-bit characters, and your application must interpret MBCS lead and
Trail bytes itself.

CstringObjects also have the following characteristics:

(1) cstringObjects can grow as a result of concatenation (concatenation) operations.

(2) cstringObjects follow "value semantics." think ofCstring
Object as an actual string, not as a pointer to a string.

(3)You can freely substitute (replace)CstringObjectsConst char *And
LpctstrFunction arguments.

(4)A Conversion operator gives direct access to the string's characters as
Read-Only array of characters (a C-style string ).

tip where possible, allocate cstring objects on the frame
rather than on the heap. this saves memory and simplifies parameter passing.

cstring assists you in conserving memory space by allowing two strings
sharing the same value also to share the same buffer space. however, if you
attempt to change the contents of the buffer directly (not using MFC), you can
alter both strings unintentionally. cstring provides two member
Functions, cstring: lockbuffer
and cstring: unlockbuffer, to
help you protect your data. when you call lockbuffer , you create a copy
of a string, then set the reference count to-1, which "locks" the buffer. while
the buffer is locked, no other string can reference the data in that string, and
the locked string will not reference another string. by locking the string in
the buffer, you ensure that the string's exclusive hold on the data will remain
intact. when you have finished with the data, call unlockbuffer to reset
the reference count to 1.

For details, see msdn ..... Haha.

C ++ self-implemented cstring class:







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.