locked
CString behavior in VC6.0 and VS2010 RRS feed

  • Question

  • Hi All,

    I have observed the following behavior in “CString”. In VC 6.0  CString is a normal class  but in VS2010 “CString” is a Class Template(ATL::CString). There is some difference in the behavior of CString methods in VC 6.0 and VS2010. 

    The concatenation (A =A+B) and operator overloading (A+=B) are behaving differently in VC6.0 and VS2010. I have created sample MFC project in VC6.0 and VS2010 to reproduce this issue.

    Code:

    CString strTemp = _T("");

           CString strVar1 = _T("");

           CString strVar2 = _T("");

           BYTE b[5] = { 0x12, 0x33, 0x00, 0x23, 0x22};

           for(int i=0;i<5;i++)

           {

                  strTemp.Format("%c",b[i]);

                  strVar1 += strTemp;

                  strVar2 = strVar2 + strTemp;

           }

           int len1 = strVar1.GetLength();

           int len2 = strVar2.GetLength();

           AfxMessageBox(strVar1);

           AfxMessageBox(strVar2);

    Observed Behavior:

    CString behaviour in VC 6.0 and VS2010

    Thanks,

    Vijay

    Thursday, March 13, 2014 7:11 AM

Answers

All replies