c++求调试,,我想连接两个字符串

来源:百度知道 编辑:UC知道 时间:2024/06/01 16:32:27
#include<iostream.h>
#include<string>
void connet(char *p1,char *p2)
{
int len1=strlen(p1);
while(*p2!='\0')
{
int len=strlen(p1);
*(p1+len)++=*p2++;

}

}
void main()
{
char *p1="I am",*p2=" a boy";

cout<<p1;
}

为什么不用string.
string 重载了"+"号,连接字符串非常方便.

如果有char* p;char *q则可以string s1=p;string s2=q;
然后,string s3=s1+s2;
cout<<s3即可.

为什么老用char,char[],char *呢...

string 更加安全快捷.

Remarks
If an application attempts to delete a file that does not exist, the DeleteFile function fails.

Use the RemoveDirectory function to delete a directory.

The DeleteFile function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file.

To close an open file handle, use the CloseHandle function.

To unmount a database volume, use the CeUnmountDBVol function

删除一个不存在的文件,或者删除一个刚刚打开还没有关闭的文件是会出错

*(p1+len)++;
p1+len不是变量, 不能执行++操作
改成*((p1++)+len) = *p2++;