CString类的用法介绍和自己动手写的CString类
2009-03-13 15:12
351 查看
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, CString is enabled for multibyte
character sets (MBCS, also known as double-byte character sets, DBCS). Note that
for MBCS strings, CString still counts, returns, and manipulates strings
based on 8-bit characters, and your application must interpret MBCS lead and
trail bytes itself.
CString objects also have the following characteristics:
(1)CString objects can grow as a result of concatenation(串联) operations.
(2)CString objects follow “value semantics.” Think of a CString
object as an actual string, not as a pointer to a string.
(3)You can freely substitute(替换) CString objects for const char* and
LPCTSTR function arguments.
(4)A conversion operator gives direct access to the string’s characters as a
read-only array of characters (a C-style string).
[b]Tip[/b] 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.
详细介绍见MSDN。。。。。 呵呵。
C++自己实现的CString类:
_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, CString is enabled for multibyte
character sets (MBCS, also known as double-byte character sets, DBCS). Note that
for MBCS strings, CString still counts, returns, and manipulates strings
based on 8-bit characters, and your application must interpret MBCS lead and
trail bytes itself.
CString objects also have the following characteristics:
(1)CString objects can grow as a result of concatenation(串联) operations.
(2)CString objects follow “value semantics.” Think of a CString
object as an actual string, not as a pointer to a string.
(3)You can freely substitute(替换) CString objects for const char* and
LPCTSTR function arguments.
(4)A conversion operator gives direct access to the string’s characters as a
read-only array of characters (a C-style string).
[b]Tip[/b] 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.
详细介绍见MSDN。。。。。 呵呵。
C++自己实现的CString类:
相关文章推荐
- 自己动手写处理器开篇介绍
- 自己动手写一个推荐系统,推荐系统小结,推荐系统:总体介绍、推荐算法、性能比较, 漫谈“推荐系统”, 浅谈矩阵分解在推荐系统中的应用
- 电话机有些故障,用户完全可以自己修好。下面介绍几例,读者遇到类似情况,可以自己动手试试。
- 自己动手写处理器开篇介绍
- 自己动手写处理器之第二阶段(2)——Verilog HDL简单介绍
- 《自己动手写Docker》书摘之二---Linux Cgroups介绍
- 自己动手写一个推荐系统,推荐系统小结,推荐系统:总体介绍、推荐算法、性能比较, 漫谈“推荐系统”, 浅谈矩阵分解在推荐系统中的应用
- 自己动手写处理器之第一阶段(3)——MIPS32指令集架构简单介绍
- 自己动手写CPU之第八阶段(1)——转移指令介绍
- 【ASP.NET Core快速入门】(八)Middleware管道介绍、自己动手构建RequestDelegate管道
- 《自己动手写Docker》书摘之三---Union File System介绍
- VC中的CString类用法,来自网络,自己学习用
- 菜鸟入门【ASP.NET Core】8:Middleware管道介绍、自己动手构建RequestDelegate管道
- background-position 用法详细介绍[转帖]
- java native2ascii的用法介绍
- 小编教新手怎么自己动手对系统进行安装
- Windows API介绍及用法:CreateFileMapping和MapViewOfFile函数
- 自己动手编译android gdbserver 最新版 推荐
- easyui datagrid detailview(subgrid)一些用法介绍