本文共 589 字,大约阅读时间需要 1 分钟。
CString GetBuffer() 与releasebuffer()的使用 getbuffer是为了让你使用CString类中,保存字符串缓冲区的那块指针. 至于releasebuffer,在MSDN中有这样一句话. If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions. 在对GetBuffer返回的指针使用之后需要调用ReleaseBuffer,这样才能使用其他Cstring的operations。否则会发生错误. GetBuffer可以获得一个字符数组让你能够方便的对其进行操作,调用GetBuffer以后必须调用ReleaseBuffer释放,否则不能对该CString对象进行操作譬如 CString str = "abcd" char * lpBuf = str.GetBuffer(0); lpBuf[1] = 'e'; int nLen = str.GetLength(); // 出错,ReleaseBuffer前不能进行类似的操作 str.ReleaseBuffer(); // 此时str="aecd转载地址:http://aqosi.baihongyu.com/