Wednesday, June 4, 2008

Copy and cat the string (Char*) in C++

char* newname=new char[100];
char* new="new";
char* name="name";
//first you need strcpy to copy content to newname. You can't use strcat instead of strcpy first.
strcpy(newname,new);//newname="new"
//Now you can use strcat to cat the string. But be careful about the string length.. Max length is 100-1..
strcat(newname,name);//newname="newname"

if(newname)
{delete[] newname;}

No comments: