Here introduces C-style 'string' (mostly char[]) operation.
It's important that with classes and many more useful and Memory Safe functions, string shall not be processed with these functions.
-
strcpy(dst,source),return dstcopy source to destination, returning the address of destination. be cautious that it can cause memory leak. example:char b[5]={0};char a[]="abcdefghijklmn";cout << (int)strcpy(b,a);you'll get an address.cout << ' ';for(int i = 0;i<=15;i++)cout<<b[i];returns:
1
26422204 abcdefghijklmn#
#:memory leak^ -
strncpy(dst,src,n),return dstcopy n characters at most from source to destination. returning the address of destination. (better than strcpy to avoid memory leak.) -
strcat(dst,src),return dstadd src to the end of dst. Returning the address of dst. -
strncat(dst,src,n),return dstanalogise with 2. -
strlen(s),return intlength of a string(to the \0, not the size of a list). -
strcmp(s1,s2),return intreturn (s1-s2). -
strncmp(s1,s2,n),return int,anal. with 2. -
strchr(s,ch),return addrreturn the address of the first ch in s.example:
char a[]="abcdefghijklmn";cout<<strchr(a,'f');returns:6422278example:
char a[]="abcdefghijklmn";cout<<(int)strchr(a,'q');returns:0 -
strrchr(s,ch),return addrreturn the address of the last ch in s. -
strstr(s1,s2),return addranal with 7,but finding s2.