Debug todayProgramThe value cstring. getlength In the CS ring object is 0,CodeAs follows:
Cstring m_sername;
Cstring S = "hello"
M_sername = s;
S. getlength () = 0;
Find the cause on the Internet in str1.releasebuffer (); in fact, cstring: releasebuffer is just an image, and it is the name corresponding to getbuffer.
Let's take a look at the releasebuffer code in MFC:
Void releasebuffer (INT nnewlength =-1)
{
If (nnewlength =-1)
{
Nnewlength = stringlength (m_pszdata );
}
Setlength (nnewlength );
}
Obviously, releasebuffer only plays a role in updating the length of a string. In cstring, getlength does not calculate the string length dynamically, but is calculated and saved in an int variable after the value assignment operation. When cstring is directly modified through getbuffer, the Int variable cannot be updated automatically, so the releasebuffer is available.
Therefore, the above Code adds S. releasebuffer (); and then S. getlength () is OK.
Please refer to the following link for more information: http://iqnix.blog.163.com/blog/static/217219820098441153853/. thank you !!