当前位置:网站首页>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)
{
边栏推荐
- Solve the problem that pushgateway data will be overwritten by multiple push
- Global and Chinese markets for indoor HDTV antennas 2022-2028: Research Report on technology, participants, trends, market size and share
- XWiki安装使用技巧
- Concurrency-02-visibility, atomicity, orderliness, volatile, CAS, atomic class, unsafe
- App global exception capture
- 秒杀系统1-登录功能
- 驱动与应用程序通信
- Reentrantlock usage and source code analysis
- Win10 enterprise 2016 long term service activation tutorial
- 视觉上位系统设计开发(halcon-winform)-2.全局变量设计
猜你喜欢

Tensorflow realizes verification code recognition (I)

Characteristics of MySQL InnoDB storage engine -- Analysis of row lock
![[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer](/img/9b/6ca8375ef8689a80d437665909ae30.png)
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer

求字符串函数和长度不受限制的字符串函数的详解

Kubernetes will show you from beginning to end

详解指针进阶2

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

Visual upper system design and development (Halcon WinForm) -1 Process node design

Digital image processing -- popular understanding of corrosion and expansion

运维体系的构建
随机推荐
GCC cannot find the library file after specifying the link library path
Chapter 04_ Logical architecture
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
北京共有产权房出租新规实施的租赁案例
Popular understanding of ovo and ovr
Summary of concurrent full knowledge points
Unity hierarchical bounding box AABB tree
Redis主从、哨兵、集群模式介绍
Visual upper system design and development (Halcon WinForm) -1 Process node design
SQL server installation location cannot be changed
Jvm-04-runtime data area heap, method area
视觉上位系统设计开发(halcon-winform)-4.通信管理
Can‘t connect to MySQL server on ‘localhost‘
阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
Using notepad++ to build an arbitrary language development environment
基于SVN分支开发模式流程浅析
Nppexec get process return code
Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"
使用JMeter对WebService进行压力测试
The method of parameter estimation of user-defined function in MATLAB