当前位置:网站首页>CString getbuffer and releasebuffer instructions
CString getbuffer and releasebuffer instructions
2022-07-03 15:26:00 【Yulong_】
Let's start with a piece of code :
#include <atlstr.h>
// test CString
int main(int argc, _TCHAR* argv[])
{
CStringA strTemp = "555";
// The output here is 3, No terminator
printf("str=%s,len=%d\n",strTemp.GetBuffer(),strTemp.GetLength());
LPSTR lpStr = strTemp.GetBuffer(10);
// The output here is 3, Because of GetBuffer The return value of , Not invoked ReleaseBuffer,GetLength() The returned result will be incorrect
strcpy(lpStr,"666666");
printf("str=%s,len=%d\n",strTemp.GetBuffer(),strTemp.GetLength());
strTemp.ReleaseBuffer();
// Because the call ReleaseBuffer,GetLength() The returned result is 6
printf("str=%s,len=%d\n",strTemp.GetBuffer(),strTemp.GetLength());
system("pause");
return 0;
}Running results :

ReleaseBuffer Source code :
void ReleaseBuffer(_In_ int nNewLength = -1)
{
边栏推荐
猜你喜欢

Can‘t connect to MySQL server on ‘localhost‘

redis缓存穿透,缓存击穿,缓存雪崩解决方案

Kubernetes带你从头到尾捋一遍

Matplotlib drawing label cannot display Chinese problems

整形和浮点型是如何在内存中的存储

Visual upper system design and development (Halcon WinForm) -4 Communication management
![[probably the most complete in Chinese] pushgateway entry notes](/img/5a/6dcb75f5d713ff513ad6842ff53cc3.png)
[probably the most complete in Chinese] pushgateway entry notes

Basic SQL tutorial

VS2017通过IP调试驱动(双机调试)

函数栈帧的创建和销毁
随机推荐
秒杀系统2-Redis解决分布式Session问题
【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
QT common sentence notes
Can‘t connect to MySQL server on ‘localhost‘
使用JMeter对WebService进行压力测试
视觉上位系统设计开发(halcon-winform)-2.全局变量设计
Halcon与Winform学习第一节
秒杀系统3-商品列表和商品详情
Halcon与Winform学习第二节
UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
开启 Chrome 和 Edge 浏览器多线程下载
阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
Kubernetes带你从头到尾捋一遍
自定义注解
Kubernetes 进阶训练营 Pod基础
[combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya
Jvm-05-object, direct memory, string constant pool
How are integer and floating-point types stored in memory
视觉上位系统设计开发(halcon-winform)-3.图像控件
使用Tengine解决负载均衡的Session问题