
























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 | 6422204 abcdefghijklmn# |
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 dst analogise 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:
6422278
example:
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.
Author: Victrid
Permanent Link: https://victrid.dev/2019/c-style-string-operation/
License: Copyright (c) 2025 victrid Terms of Use
Read our privacy policy on how these personalized advertisements are delivered to you.
For your reading experience, we provide full-text RSS feeds. Although math formulas cannot be displayed well, the interface can be adjusted as you like and there are no ads.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。