16,471
社区成员
发帖
与我相关
我的任务
分享
char a[1000];
CString s1 = "this is the first string value";
CString s2 = "this is the second string value";
if(s1.GetLength() < 1000)
strcpy_s(a, s1);
if (s2.GetLength() + strlen(a) < 1000)
strcat_s(a, s2);
CString s1("1234"), s2("5678");
CStringA sa;
//缓冲区长度
const int iBufLen = 1000;
//缓冲区
char chBuf[iBufLen];
//缓冲区清零
chBuf[0] = chBuf[1] = 0;
//偏移量
int iOfst = 0;
//追加s1
sa = s1;
strcpy_s(chBuf + iOfst, iBufLen - iOfst - 2, sa);
//更新长度
iOfst += sa.GetLength();
//追加'\0'
chBuf[iOfst++] = 0;
//追加sn
sa = s2;
strcpy_s(chBuf + iOfst, iBufLen - iOfst - 2, sa);
//更新长度
iOfst += sa.GetLength();
//追加'\0'
chBuf[iOfst++] = 0;
//结尾再添加一个0, 以两个0结束
chBuf[iOfst++] = 0;
strcpy_s(a, CStringA(s1));
strcat_s(a, CStringA(s2));