Difference between <cstring> and <string>
The cstring
header provides functions for dealing with C-style strings — null-terminated arrays of characters. This includes functions like strlen
and strcpy
. It's the C++ version of the classic string.h
header from C.
The string
header provides the std::string
class and related functions and operators.
The headers have similar names, but they're not really related beyond that. They cover separate tasks.
<cstring>
has the C string code from the C header string.h. C++
has a convention where C
headers have the same base name, except for a leading c
and no trailing .h
. All the contents are available under the std::
namespace.
<string>
has the standard library std::string
and related functions
In C++, you wouldn't use #include <somefile.h>
, but instead #include <somefile>
. Now C++ has its string classes in <string>
, but the c-string functions are also available, which would be in <string.h>
. C++ uses for 'traditional' c- include files. Therefore, <cstring>
and <string>
http://www.cplusplus.com/reference/clibrary/cstring/