我的代码如下:
GetPrivateProfileString("DATABASE","SERVICENAME","",strServiceName.GetBuffer(20),256,exeFullPath);
CString strConn="USER/PASS@"+strServiceName;
调试时把鼠标移到strServiceName上时看到变量得到的字符串是正确的(为“SVR”),但是没有赋给strConn,strConn的值仍然是“USER/PASS@”,为什么这样?strConn应该是“USER/PASS@SVR”才对阿.

解决方案 »

  1.   

    用这个试试:
    CString strtemp;
    strtemp = "USER/PASS@";
    CString strConn = strtemp + strServiceName;
      

  2.   

    smallbull(黑牛) :你的方法我也试过了不行
    strConn的值仍然是“USER/PASS@”
      

  3.   

    strConn.Format("%s%s","USER/PASS@",strServiceName);
      

  4.   

    那就再看这个,我就不信了:
    CString strtemp;
    char  *strchar;
    strtemp = "USER/PASS@";
    strchar = new char[strtemp.GetLength()+strServiceName.GetLength()+2];
    strcpy(strchar,strtemp.GetBuffer(strtemp.GetLength()));
    strcat(strchar,strServiceName.GetBuffer(strServiceName.GetLength()));
    CString strConn = strchar;
    delete strchar;
      

  5.   

    谢谢xuanzg(小钢娃),问题解决,但你知道为什么我原来的不行啊?