当前位置:网站首页>CString的GetBuffer和ReleaseBuffer使用说明
CString的GetBuffer和ReleaseBuffer使用说明
2022-07-03 15:20:00 【宇龍_】
先看一段代码:
#include <atlstr.h>
//测试CString
int main(int argc, _TCHAR* argv[])
{
CStringA strTemp = "555";
//这里输出为3,不包含结束符
printf("str=%s,len=%d\n",strTemp.GetBuffer(),strTemp.GetLength());
LPSTR lpStr = strTemp.GetBuffer(10);
//这里输出为3,因为对GetBuffer的返回值进行了操作,未调用ReleaseBuffer,GetLength()返回结果将不正确
strcpy(lpStr,"666666");
printf("str=%s,len=%d\n",strTemp.GetBuffer(),strTemp.GetLength());
strTemp.ReleaseBuffer();
//由于调用了ReleaseBuffer,GetLength()的返回结果就为6
printf("str=%s,len=%d\n",strTemp.GetBuffer(),strTemp.GetLength());
system("pause");
return 0;
}运行结果:

ReleaseBuffer源码:
void ReleaseBuffer(_In_ int nNewLength = -1)
{
边栏推荐
- 【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
- Influxdb2 sources add data sources
- [daily training] 395 Longest substring with at least k repeated characters
- 高并发下之redis锁优化实战
- redis单线程问题强制梳理门外汉扫盲
- Global and Chinese markets for indoor HDTV antennas 2022-2028: Research Report on technology, participants, trends, market size and share
- Reentrantlock usage and source code analysis
- Calibre LVL
- Visual upper system design and development (Halcon WinForm) -6 Nodes and grids
- Kubernetes - YAML文件解读
猜你喜欢

详解指针进阶1
![[probably the most complete in Chinese] pushgateway entry notes](/img/5a/6dcb75f5d713ff513ad6842ff53cc3.png)
[probably the most complete in Chinese] pushgateway entry notes

Halcon and WinForm study section 1
![[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention](/img/94/a9c7010fe9f14454469609ac4dd871.png)
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention

视觉上位系统设计开发(halcon-winform)-3.图像控件
![[cloud native training camp] module VIII kubernetes life cycle management and service discovery](/img/87/92638402820b32a15383f19f6f8b91.png)
[cloud native training camp] module VIII kubernetes life cycle management and service discovery

Basic SQL tutorial

Seckill system 3- product list and product details

秒杀系统1-登录功能

mysql innodb 存储引擎的特性—行锁剖析
随机推荐
Functional modules and application scenarios covered by the productization of user portraits
Visual host system design and development (Halcon WinForm)
High quality workplace human beings must use software to recommend, and you certainly don't know the last one
[probably the most complete in Chinese] pushgateway entry notes
Qt常用语句备忘
leetcode_ Power of Four
Tensorflow realizes verification code recognition (III)
【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
Reentrantlock usage and source code analysis
Enable multi-threaded download of chrome and edge browsers
Using Tengine to solve the session problem of load balancing
Dataframe returns the whole row according to the value
el-switch 赋值后状态不变化
Stress test WebService with JMeter
视觉上位系统设计开发(halcon-winform)-2.全局变量设计
Search in the two-dimensional array of leetcode sword offer (10)
The first character of leetcode sword offer that only appears once (12)
Unity hierarchical bounding box AABB tree
第04章_逻辑架构
mysql innodb 存储引擎的特性—行锁剖析