CString

摘要:
______CString::左侧。返回值:包含指定字符范围副本的ACString对象。请注意,返回的cString对象可能为空//示例CString::LeftCStrings(_T(“abcdef”));ASSERT(左)(

______CString::Left.

Return Value:   CString object containing a copy of the specified range of characters. Note that the returnedCString object may be empty.

// example for CString::Left
CString s( _T("abcdef") );
ASSERT( s.Left(2) == _T("ab") );

//int GetLength( ) const;The count does not include a null terminator.
int c = s.GetLength();
//LPTSTR GetBuffer( int nMinBufLength );
nMinBufLength does not include a null terminator.
LPTSTR p = s.GetBuffer(c);

Returns a pointer to the internal character buffer for the CString object. The returned LPTSTR is not const and thus allows direct modification of CString contents.

If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions.

The address returned by GetBuffer may not be valid after the call to ReleaseBuffer since additional CStringoperations may cause the CString buffer to be reallocated. The buffer will not be reallocated if you do not change the length of the CString.

The buffer memory will be freed automatically when the CString object is destroyed.

Note that if you keep track of the string length yourself, you should not append the terminating null character. You must, however, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating null character, you should pass –1 for the length to ReleaseBuffer and ReleaseBuffer will perform astrlen on the buffer to determine its length.

Example

The following example demonstrates the use of CString::GetBuffer.

// example for CString::GetBuffer
CString s( "abcd" );
#ifdef _DEBUG
afxDump << "CString s " << s << "
";
#endif
LPTSTR p = s.GetBuffer( 10 );
strcpy( p, "Hello" );   // directly access CString buffer
s.ReleaseBuffer( );
#ifdef _DEBUG
afxDump << "CString s " << s << "
";
#endif
 

免责声明:文章转载自《CString》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇PostgreSQL连接python,postgresql在python 连接,创建表,创建表内容,插入操作,选择操作,更新操作,删除操作。Python -扩展C++-Pytorch扩展下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

MFC-CString与int互相转化

1. CString转int int n = 0; CString str = _T("123"); n = _ttoi(str); 2. int转CString int n = 0; CString str; str.Format(_T(%d) , n); 参考:MFC中 CString与int的转化 vs2010 中 MFC::CString...

【原】结构体包含CString类型成员变量出错的原理

问题如下:我定义了如下的一个结构体:typedef struct{CString csText;}MyStruct;并有如下的程序段1:MyStruct * p=NULL;p=(MyStruct *)malloc(sizeof(MyStruct));if(!p)AfxMessageBox("分配内存失败!");else{p->csText="hell...

VC++-数据加密

版本: VS2012 实例说明: 在一些应用程序或网络程序中,经常会存有一些非常机密的文件或数据,为了防止其他非法用户查阅或盗取这些机密数据,可对其进行加密。运行程序,在“密钥”编辑框中输入密钥,在“待加密的字符串”编辑框中输入要加密的字符串,单击“加密”按钮,密文将显示在“加密后的字符串”编辑框中,如图所示。 界面: 技术要点: 通过使用GetAt和S...

CFile和CStdioFile的文件读写使用方法

CFile//创建/打开文件CFile file;file.Open(_T("test.txt"),CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite); 文件打开模式可组合使用,用“|”隔开,常用的有以下几种:CFile::modeCreate:以新建方式打开,如果文件不存在,新建;如...

CString之Find()、FindOneOf()、ReverseFind()

一、CString之Find()、FindOneOf()、ReverseFind() 此三个函数返回值均为整数int。 1、Find() 该函数从左侧0索引开始,查找第一个出现的字符位置,返回position。示例如下: 1 CString s("abcd"); 2 ASSERT( s.Find('b') == 1 ); 返回值:...

char *内容输出

//test{int i;int width = 32;CString tmp;CString str0; for(i=0; i<len; i++){//tmp.Format(L"%6.6X", i);tmp.Format(L"%2.2X ", (unsigned char)pData[i]);str0+=tmp;} str0 = str0;TRAC...