I noticed that there was (at least on Mac OS X) both a <string.h>
header and a <strings.h>
header. man 3 string
reveals that they contain different functions. Is there any reason for this?
h> just adds some useful but non-standard additional string functions to the standard header <string. h> . For maximum portability you should only use <string. h> but if you need the functions in <strings.
<string. h> contains old functions like strcpy , strlen for C style null-terminated strings. <string> primarily contains the std::string , std::wstring and other classes.
h is the header in the C standard library for the C programming language which contains macro definitions, constants and declarations of functions and types used not only for string handling but also various memory handling functions; the name is thus something of a misnomer. Functions declared in string.
You don't need to include any headers for it. But there is a possibility to avoid using <string. h> for certain compilers. See commit, which fixed compiler errors for cross-compiling on android, which added <string.
strings.h comes from the BSD branch in the unix evolution. Its content has been standardized by POSIX, but most of it is marked as legacy and can be easily replaced with other functions:
int bcmp(const void *, const void *, size_t); /* LEGACY, see memcmp */ void bcopy(const void *, void *, size_t); /* LEGACY, see memcpy, memmove */ void bzero(void *, size_t); /* LEGACY, see memset */ int ffs(int); char *index(const char *, int); /* LEGACY, see strchr */ char *rindex(const char *, int); /* LEGACY, see strrchr */ int strcasecmp(const char *, const char *); int strncasecmp(const char *, const char *, size_t);
Typically <strings.h>
just adds some useful but non-standard additional string functions to the standard header <string.h>
. For maximum portability you should only use <string.h>
but if you need the functions in <strings.h>
more than you need portability then you can use <strings.h>
instead of <string.h>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With