What is the difference between string.h
and cstring
?
Which one should be used for C and which one for C++ (if at all)?
There is a subtle difference between string.h and cstring
Answer of Alf P. Steinbach (can be found as a comment to the asked question):
string.h
places the identifiers in the global namespace, and may also place them in the standard namespace. While cstring
places the identifiers in the standard namespace, and may also place them in the global namespace. You definitely don't want that cstring
behavior, because code that e.g. uses just strlen
may work fine with one compiler, then fail to compile with another compiler. It's very unpleasant surprise. So for C and C++, use the more safe string.h
.