In C++ you should include
cstring as the header while in c you should include
string.h as the header.
Features of C standard Library are also provided in the C++ Standard library and as a general naming convention they are pre-pended by an
c to the corresponding names in C standard library.
cstdio and so on...
Since other answers have added different dimensions to this discussion,I felt compelled to refer the holy standard to clear ths bit.
As per C++11 18.104.22.168 & 7:
Table 55 describes the header
The contents are the same as the Standard C library header , with the change to
memchr() specified in 21.7.
While 21.7 Null-terminated sequence utilities states:
The function signature
memchr(const void*, int, size_t) shall be replaced by the two declarations:
const void* memchr(const void* s, int c, size_t n);
void* memchr( void* s, int c, size_t n);
both of which shall have the same behavior as the original declaration.
Annex D (normative) Compatibility features [depr] states:
D.6 C standard library headers
1 For compatibility with the C standard library and the C Unicode TR, the C++ standard library provides the 25 C headers, as shown in Table 151.
<assert.h> <float.h> <math.h> <stddef.h> <tgmath.h>
<complex.h> <inttypes.h> <setjmp.h> <stdio.h> <time.h>
<ctype.h> <iso646.h> <signal.h> <stdint.h> <uchar.h>
<errno.h> <limits.h> <stdarg.h> <stdlib.h> <wchar.h>
<fenv.h> <locale.h> <stdbool.h> <string.h> <wctype.h>
2 Every C header, each of which has a name of the form
name.h, behaves as if each name placed in the standard library namespace by the corresponding
cname header is placed within the global namespace scope. It is unspecified whether these names are first declared or defined within namespace scope (3.3.6) of the namespace std and are then injected into the global namespace scope by explicit using-declarations (7.3.3).
3 [ Example: The header
<cstdlib> assuredly provides its declarations and definitions within the namespace std. It may also provide these names within the global namespace. The header
<stdlib.h> assuredly provides the same declarations and definitions within the global namespace, much as in the C Standard. It may also provide these names within the namespace std. —end example ]
From the above references:
I stand corrected on my earlier suggestion, there seems to be no apparent advantage of using
string.h while as @Alf suggested there might be some compilation issues due to use of unqualified function names when using
cstring as header. So given hat there is no apparent dis-advantage of using
string.h or advantage of using
cstring, I think either can be used in C++ if used in a proper manner.