开发者

How to add CString to const char*?

开发者 https://www.devze.com 2023-03-16 06:27 出处:网络
How to append a CString to a const char*? 开发者_如何转开发CString custompath = \"c:\\folder\\\";

How to append a CString to a const char*?

开发者_如何转开发CString custompath = "c:\folder\";
const char *one = "IECapt.exe --url=";


Try reading this.

There, you can find some suggestions on how to obtain what you want. E.g. you can use this snippet:

int     sizeOfString = custompath.GetLength();   // as in the example
size_t  destsize = sizeOfString + strlen(one) + 1;
LPTSTR  lpsz = new TCHAR[ destsize ];
_tcscpy_s(lpsz, destsize, theString);
_tcscpy_s(lpsz + sizeOfString, strlen(one)+1, one);
CString completePath(lpsz);

Then you can delete lpsz, if you don't need it anymore. Or, rather, you could do something like the following, from the idea (just the idea) in the section Modifying CString Contents Directly:

 LPTSTR pBuf = custompath.GetBufferSetLength(custompath.GetLength() + strlen(one) + 1);
 _tcscpy_s(pBuf + custompath.GetLength(), strlen(one) + 1, one);
 custompath.ReleaseBuffer();
0

精彩评论

暂无评论...
验证码 换一张
取 消