注册 登录
编程论坛 VC++/MFC

为什么strcpy不能将CString类的对象里的字符给char数组?各位帮忙看下我的程序有什么问题。

a2010woshish 发布于 2011-05-19 13:46, 714 次点击
我是要把CODELIST列表框的内容给temp,然后把temp给数组SS,中间一大段是将SS里的GO1 GO2 GO3 换成MOV CIRCW CIRCCW,再把改后的SS给temp,最后把temp 的内容显示到ACRLIST列表框里。错误是:error C2664: 'strcpy' : cannot convert parameter 1 from 'class CString' to 'char *'。程序如下:
CString temp;
int k;
char SS[100];
for(k=0;k<m_codeList.GetCount();k=k+1)
{
    m_codeList.GetText(k,temp);
    strcpy(SS,temp);
    char *p=SS;
    int n=strlen(SS);
    int i=0,j=0;
    while(*p!=NULL)
    {
    //    if(*p=='F')
        switch(*p)
        {   
         case 'G':
             switch(*(p+1))
             {
              case '0':
                   switch(*(p+2))
                   {
                    case '1':
                       *p='M';
                       *(p+1)='O';
                       *(p+2)='V';
                       break;
                    case '2':
                       for(j=0;j<n-i;j++)
                       *(p+n-i-j+2)=*(p+n-i-j);
                       *p='C';
                       *(p+1)='I';
                       *(p+2)='R';
                       *(p+3)='C';
                       *(p+4)='W';
                       break;
                    case '3':
                       for(j=0;j<n-i;j++)
                       *(p+n-i-j+3)=*(p+n-i-j);
                       *p='C';
                       *(p+1)='I';
                       *(p+2)='R';
                       *(p+3)='C';
                       *(p+4)='C';
                       *(p+5)='W';
                       break;
                   }
             break;
             }
        break;
        }
        p++;
        i++;
   
    }
    strcpy(temp,SS);
    UpdateData(true);
    m_acrList.InsertString(m_acrList.GetCount(), temp);
    m_codeStr = "";
    UpdateData(false);

}
2 回复
#2
yuccn2011-05-19 18:14
char szText[64] = { 0 };
CString s(_T("File.ext"));
LPTSTR p = s.GetBuffer();

strcpy(szText, p);

s.ReleaseBuffer();
#3
debroa7232011-05-19 22:04
strcpy_s(szText,64, s.GetBuffer());

1